提前感谢您的回复。我想使用javascript禁用IE的查看源码快捷键。要禁用"Ctrl + C",我使用以下I函数:
function disableCopy() {
// current pressed key
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && (pressedKey == "c")) {
// disable key press porcessing
event.returnValue = false;
}
}有谁能建议如何禁用Alt+V+C组合吗?
发布于 2012-07-11 21:27:57
每种浏览器都有自己的内置功能,可以查看源代码或网页。我们可以做一件事。这就是在你的页面上禁用右键点击。
对于禁用右键单击,请使用以下代码:
<SCRIPT TYPE="text/javascript">
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</SCRIPT>记住一件事。我们可以使用firebug或其他一些第三方工具来查看此源代码。所以我们不能100%这样做。
发布于 2012-07-11 21:39:33
您不应该真的阻止查看代码。为什么?
原因
禁用组合
document.onkeydown = function(e) {
if (e.altKey && (e.keyCode === 67||e.keyCode === 86)) {//Alt+c, Alt+v will also be disabled sadly.
alert('not allowed');
}
return false;
};不管怎样,因为我知道怎么做,所以我会教你。
此处要禁用右键单击:
function clickIE() {if (document.all) {return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false") 发布于 2012-07-11 21:51:04
alt +V+C是一个非常奇怪的组合。尽管下面的代码可以正常工作,但它有点像黑客。
if (event.altKey) {
if (event.keyCode == 67 && window.prevKey == 86)
event.preventDefault();
else if (event.keyCode == 86 && window.prevKey == 67)
event.preventDefault();
window.prevKey = event.keyCode
}https://stackoverflow.com/questions/11433647
复制相似问题