有趣的问题。我想知道这是可能也和具有以下想出了:
注意:代码可能不会#2或任何其他服务,可容纳代码,由于它在沙盒环境中运行工作。如果你打开你的控制台,你可能会看到警告,告诉你它已经阻止了弹出窗口。要访问控制台:
铬
按Ctrl /命令 + 移位/选项 + Ĵ
火狐
按Ctrl /命令 + 移/选项 + ķ
$(function() {
$('.my-element').on('click contextmenu', function(e) {
// If the right mouse button is used
if (e.which === 3) {
// Grab data-link value from <div>
var link = $(this).data('link');
// Open new tab
window.open(link, '_blank');
}
// Cancel default right click behavior
return false;
});
});
.my-element {
width: 200px;
height: 200px;
color: white;
background: tomato;
font: bold 1em sans-serif;
text-align: center;
line-height: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="my-element" data-link="https://www.google.com">Right click here</div>
这可能会有所帮助:如何鼠标左右区分点击使用jQuery(http://stackoverflow.com/questions/1206203/how在左键和右键之间进行区分 - 用jquery) – showdev