禁用一次后启用上下文菜单
Enable contextmenu after disabling it once
我正在做一个过去有一些学生做过的项目,因此代码质量没有达到应有的水平。我正在尝试启用用户右键单击时出现的上下文菜单,但它没有发生。
Link: Click here to visit the project
我已经尝试了以下应该反转任何 preventDefault() 函数的方法,但它不起作用。解决这个问题应该很简单,但不知何故上下文菜单不会显示。有什么想法吗?
$(window).bind("contextmenu", function () {
return true;
});
我找不到上下文菜单首先被禁用的原因,因此也找不到这个解决方案。我也用 'body' 试过,它也不起作用。
document.oncontextmenu = null;
足以杀死它(在这种情况下),但请确保在调用该脚本后调用它:
您也可以从正文(顶部)中删除此代码:
<script type="text/javascript">
document.oncontextmenu = function(e){
var t = e || window.event;
var elm = t.target || t.srcElement;
if(elm.nodeName == "A" || elm.type == 'text' || elm.type == 'password')
return true;
return false;
}
</script>
您可以使用unbind
Docs:
Robust and extensible applications typically demand the two-argument
version for this reason:
var handler = function() {
alert( "The quick brown fox jumps over the lazy dog." );
};
$( "#foo" ).bind( "click", handler );
$( "#foo" ).unbind( "click", handler );
By naming the handler, we can be assured that no other functions are
accidentally removed.
因此只需命名该处理程序:
var handler = function() {
return false;
};
$( window ).bind( "contextmenu", handler );
$( window ).unbind( "contextmenu", handler );
我正在做一个过去有一些学生做过的项目,因此代码质量没有达到应有的水平。我正在尝试启用用户右键单击时出现的上下文菜单,但它没有发生。
Link: Click here to visit the project
我已经尝试了以下应该反转任何 preventDefault() 函数的方法,但它不起作用。解决这个问题应该很简单,但不知何故上下文菜单不会显示。有什么想法吗?
$(window).bind("contextmenu", function () {
return true;
});
我找不到上下文菜单首先被禁用的原因,因此也找不到这个解决方案。我也用 'body' 试过,它也不起作用。
document.oncontextmenu = null;
足以杀死它(在这种情况下),但请确保在调用该脚本后调用它:
您也可以从正文(顶部)中删除此代码:
<script type="text/javascript">
document.oncontextmenu = function(e){
var t = e || window.event;
var elm = t.target || t.srcElement;
if(elm.nodeName == "A" || elm.type == 'text' || elm.type == 'password')
return true;
return false;
}
</script>
您可以使用unbind
Docs:
Robust and extensible applications typically demand the two-argument version for this reason:
var handler = function() { alert( "The quick brown fox jumps over the lazy dog." ); }; $( "#foo" ).bind( "click", handler ); $( "#foo" ).unbind( "click", handler );
By naming the handler, we can be assured that no other functions are accidentally removed.
因此只需命名该处理程序:
var handler = function() {
return false;
};
$( window ).bind( "contextmenu", handler );
$( window ).unbind( "contextmenu", handler );