积极答复者
ie8 ie9下报: 对象不支持“captureEvents”属性或方法,ie6 ie7下正常

问题
-
编程工具visual studio2012, asp.net程序
if (window.Event) document.captureEvents(Event.MOUSEUP);
function nocontextmenu() {
event.cancelBubble = true;
event.returnValue = false;
return false;
}
function norightclick(e) {
document.oncontextmenu = nocontextmenu;
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.onmousedown = norightclick;这段代码的作用是屏蔽右键功能,ie7以下都能实现,ie7以上怎么实现这功能,这段代码
在ie8 ie9下报错。
答案
-
这样修改看看,我自己测试过了:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <script src="Scripts/jquery-2.0.3.js"></script> <script> document.oncontextmenu = function () { alert("不允许右键!"); return false; } </script> </head> </html>
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已标记为答案 齐永刚 2013年9月23日 12:44
全部回复
-
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <script> function BlockRightClick() { window.oncontextmenu = function () { alert("不允许右键!"); return false; } } </script> </head> <body onload="BlockRightClick()"> </body> </html>
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已编辑 ThankfulHeart 2013年9月23日 6:03 删除冗余部分代码
-
ThankfulHeart 你好:
上面您给的那个答案不起作用,不能屏蔽右键,右击时并不会自动调用BlockRightClick()函数。
-
这样修改看看,我自己测试过了:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <script src="Scripts/jquery-2.0.3.js"></script> <script> document.oncontextmenu = function () { alert("不允许右键!"); return false; } </script> </head> </html>
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已标记为答案 齐永刚 2013年9月23日 12:44
-
ThankfulHeart 您好:
上面的回答解决了我的问题。感谢您的回答。