JS禁用右鍵,禁用打印,防止另存爲
οncοntextmenu="window.event.returnValue=false" style="overflow-y: hidden; overflow-x: hidden"ajs9 leftmargin="0" topmargin="0"
<body οncοntextmenu="return false"></body>
<!--禁止網頁另存爲: -->
<noscript><iframe src=*.html></iframe></noscript>
<!-- 禁止選擇文本: -->
<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}
function reEnable(){
return true
}
if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.οnmοusedοwn=disableselect
document.οnmοuseup=reEnable
}
</script>
<!-- 禁用右鍵: -->
<script>
function stop(){
return false;
}
document.οncοntextmenu=stop;
</script>
1. οncοntextmenu="window.event.returnvalue=false" 將徹底屏蔽鼠標右鍵
<table border οncοntextmenu=return(false)><td>no</table> 可用於Table
2. <body onselectstart="return false"> 取消選取、防止複製
3. οnpaste="return false" 不準粘貼
4. οncοpy="return false;" oncut="return false;" 防止複製
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址欄前換成自己的圖標
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夾中顯示出你的圖標
7. <input style="ime-mode:-Disabled"> 關閉輸入法
8. 永遠都會帶着框架
<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm爲框架網頁
// --></script>
9. 防止被人frame
<SCRIPT LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
11. <input type=button value=查看網頁源代碼
οnclick="window.location = `view-source:`+ http://www.tonightdream.com/`";>
12.刪除時確認
<a href=`javascript:if(confirm("確實要刪除嗎?"location="boos.asp?&areyou=刪除&page=1"`>刪除</a>
13. 取得控件的絕對位置
//javascript
<script language="javascript">
function getIE(E){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
<!--右鍵開始-->
<script language="JavaScript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
<!-- 禁止選擇文本: -->
<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}
function reEnable(){
return true
}
if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.οnmοusedοwn=disableselect
document.οnmοuseup=reEnable
}
</script>
<script language="javascript" type="text/javascript">
<!--
function key(){
if(event.shiftKey){
window.close();}
//禁止shift
if(event.altKey){
window.close();}
//禁止alt
if(event.ctrlKey){
window.close();}
//禁止ctrl
return false;}
//document.οnkeydοwn=key;
if (window.Event)
document.captureEvents(Event.MOUSEUP);
//swordmaple javascript article.
//from http://www.jx165.com/
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;}
}
//禁止右鍵
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
---------------
要真正禁止打印頁面是辦不到的,但是如果能設置讓用戶打印到的是空白,也算是實現禁止打印的目的了
<html>
<head><title>不可打印的頁面</title>
<style>
@media print{
body{display:none}
}
</style>
</head>
<body>
文檔主要內容
</html>