您的位置:首页 > Web前端 > JavaScript

js屏蔽

2016-05-24 21:24 507 查看

js屏蔽鼠标右键

oncontextmenu="window.event.returnValue=false" style="overflow-y: hidden; overflow-x: hidden"ajs9 leftmargin="0" topmargin="0"
<body oncontextmenu="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.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>
<!-- 禁用右键: -->
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="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=查看网页源代码
onclick="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.onmousedown=disableselect
document.onmouseup=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.onkeydown=key;
if (window.Event)
document.captureEvents(Event.MOUSEUP);
//swordmaple javascript article.
//from 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>


javascript 禁止右键的4种方法

方法一:

<SCRIPT language="JavaScript">

function click()

{

   if(event.button==2)

{

alert('右键不能用了!')

}

}

document.onmousedown=click

</SCRIPT>


方法二:添加到收藏夹

<SCRIPT language="JavaScript">

function click()

{

if(event.button==2)

{

window.external.addFavorite('http://blog.aq82.com','aq82,阿Q家园');

}

}

document.onmousedown=click

</SCRIPT>


方法三:使右键失效

将<body>改成<body oncontextmenu=self.event.returnValue=false>

该方法须IE5以上

方法四:

将<body>改成<body ondragstart="window.event.returnValue=false" oncontextmenu="window.event.returnValue=false" onselectstart="event.returnValue=false">

该方法使鼠标失效,效果和方法三差不多,但此时不能用鼠标选取页面上的内容,同时“编辑->全选”也没有作用。

JavaScript实现禁止右键点击的代码 function disableRightClick(e)

{

var message = "Right click disabled";

if(!document.rightClickDisabled) // initialize

{

if(document.layers)

{

document.captureEvents(Event.MOUSEDOWN);

document.onmousedown = disableRightClick;

}

else document.oncontextmenu = disableRightClick;

return document.rightClickDisabled = true;

}

if(document.layers || (document.getElementByIdx && !document.all))

{

if (e.which==2||e.which==3)

{

alert(message);

return false;

}

}

else

{

alert(message);

return false;

}

}


有时自己辛苦半天做的网页,尤其是一些javascript特效,很容易被人利用查看源文件而复制。那么如何才能防止被人查看源代码呢?我们可以利用event.button特性来做到。下表是event.button属性的可能取值及含义:

0 没按键

1 按左键

2 按右键

3 按左和右键

4 按中间键

5 按左和中间键

6 按右和中间键

7 按所有的键

参照上表,我们可以在<body>和</body>之间加入如下语句:

<Script Langvage=javascript>

function Click(){

if (event.button!=1){alert('版权所有(C)2001 XXX工作室');

}}

document.onmousedown=Click;

</Script>

这样在浏览网页时除单击鼠标左键外,其他任何形式的鼠标点击或组合点击,都将出现“版权所有(C)2001 XXX工作室”的提示框,而不是出现快捷菜单,从而避免被人查看源文件代码。

如果使event.button=2,实际上它仅能限制点击鼠标右键情况,其他点击方式,如按左右键、按左和中间键、按中间键等就不能限制,当这些方式的点击发生时,出现的就是快捷菜单,从而可以查看源文件。


注意:把body改为如下代码:<body oncontextmenu="window.event.returnValue=false">,其中Value中的V一定要大写!!

页面禁用鼠标右键代码

可以把下面代码加入到页面适当位置。

LeadBBS论坛应用下面代码时,可以打开:inc/Board_Popfun.asp文件

查找:

<script language = "JavaScript" src = "<%=DEF_BBS_HomeUrl%>inc/JF.js" type="text/javascript"></script>

下面加入代码。


<script language=javascript>

function openScript(url, width, height,left,top,r){

var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',left=' +left+ ',top='+top+',resizable=no,scrollbars='+r+',menubar=no,status=no' );

}


//以下为禁止鼠标右键的代码,不想禁止的可以删除

<!--


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) {alert("欢迎你"); } }

{

event.cancelBubble = true

event.returnValue = false;

return false;

}


}

document.oncontextmenu = nocontextmenu; // for IE5+

document.onmousedown = norightclick; // for all others

//-->

</script>

四 图片禁用鼠标右键代码


应用方法同上。

<script language="JavaScript1.2">

var clickmessage="本站图片禁用右键!"

function disableclick(e) {

if (document.all) {

if (event.button==2||event.button==3) {

if (event.srcElement.tagName=="IMG"){

alert(clickmessage);

return false;

}

}

}

if (document.layers) {

if (e.which == 3) {

alert(clickmessage);

return false;

}

}

}


function associateimages(){

for(i=0;i<document.images.length;i++)

document.images[i].onmousedown=disableclick;

}


if (document.all)

document.onmousedown=disableclick

else if (document.layers)

associateimages()

</script>


功能:禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt

<script language="JavaScript">

<!--

function key(){

if(event.shiftKey){

window.close();}

//禁止Shift

if(event.altKey){

window.close();}

//禁止Alt

if(event.ctrlKey){

window.close();}

//禁止Ctrl

return false;}

document.onkeydown=key;

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>


<body onselectstart="return false"; onpaste="return false";>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: