我想出了这个解决方案,这是非常老套和DIY,但应该做的伎俩。
诀窍是使用以下命令创建自己的上下文菜单
jQuery
插件:
https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.contextMenu.js
https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.contextMenu.css
https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.ui.position.js
这不会在上执行
SO
我建议在jsfiddle上运行它:
JSFiddle
$(function() {
$.contextMenu({
selector: '.context-menu-one',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m);
switch (key) {
case "open_new_window":
console.log($(this));
//var win = window.open($(this)[0].href, '_blank');
window.open($(this)[0].href,'_blank');
//win.focus();
break;
case "cut":
break;
}
},
items: {
"open_new_window": {
name: "Open link in new tab",
icon: "edit"
},
"cut": {
name: "Cut",
icon: "cut"
}
}
});
});
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.ui.position.js"></script>
<link href="https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.contextMenu.css" rel="stylesheet"/>
<script src="https://rawgit.com/swisnl/jQuery-contextMenu/master/dist/jquery.contextMenu.js"></script>
<a class="context-menu-one" href="https://www.google.com">Google</a><br>
<a class="context-menu-one" href="https://www.bing.com">Bing</a><br>
<a class="context-menu-one" href="https://www.yahoo.com">Yahoo</a><br>
<a class="context-menu-one" href="https://www.facebook.com">Facebook</a><br>