document.addEventListener('contextmenu', function (e) {
e.preventDefault()
e.stopPropagation()
e.returnValue = false
e.cancleBubble = true
})
編輯:document.oncontextmenu = null
不起作用。
P.S.我不能擁有監聽器功能的引用,因爲我不是阻止上下文菜單的站點的所有者。
document.addEventListener('contextmenu', function (e) {
e.preventDefault()
e.stopPropagation()
e.returnValue = false
e.cancleBubble = true
})
編輯:document.oncontextmenu = null
不起作用。
P.S.我不能擁有監聽器功能的引用,因爲我不是阻止上下文菜單的站點的所有者。
如果你真的絕望,嘗試添加此addEventListener
被調用之前。它適用於FF和Chrome。我沒有檢查其他東西。
document.superListener = document.addEventListener;
document.addEventListener = function(type, listener, useCapture){
if(type != 'contextmenu')
document.superListener(type, listener, !!useCapture);
};
它可能不是做事情的最好方法,但它應該在你的具體的例子:)
謝謝你的回答。看起來不可能重新啓用上下文菜單「之後」調用... – 2010-06-13 16:08:29
而不是禁用上下文菜單,爲什麼不分配右鍵單擊事件?
http://abeautifulsite.net/2008/05/jquery-right-click-plugin/
我不是禁用上下文菜單的人。有些網站禁用它,我想打破它。 – 2010-06-09 09:42:08
哦,你的意思是作爲一個greasemonkey腳本或什麼? – Matrym 2010-06-09 18:53:37
我用我在這種情況下,書籤來完成這項工作:
javascript:(function(w){
var arr = ['contextmenu','copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'];
for(var i = 0, x; x = arr[i]; i++){
if(w['on' + x])w['on' + x] = null;
w.addEventListener(x, function(e){e.stopPropagation()}, true);
};
for(var j = 0, f; f = w.frames[j]; j++){try{arguments.callee(f)}catch(e){}}})(window);
這一個工作正常。只需將選項限制爲「contextmenu」。 – ThiagoPonte 2016-04-27 12:36:19
工作得很好,謝謝 – 2017-03-28 10:50:29
我該如何投票10次?謝謝! – tyron 2017-05-17 03:27:32
什麼你的意思是「道德」? – 2010-06-02 22:20:14
在我看來,故意禁用上下文菜單的網站應該禁止或不運行腳本。 (我使用NoScript。)我經常通過右鍵單擊並選擇「後退」或「前進」進行導航。沒有什麼不合乎想要的上下文菜單工作。站點作者首先禁用它是愚蠢的。 – JYelton 2010-06-02 22:23:55
你有沒有試過'document.oncontextmenu = null;'? – 2010-06-02 22:44:36