jQueryを使用する場合は、単純に mousedown を使用できます。
$(document).bind('contextmenu', function(event)
{
// on right click
if (event.which == 3)
{
// prevent right click from being interpreted by the browser:
event.preventDefault();
$(document).mousedown(); // simulate left click
}
});
もちろん、フィッティング セレクターを使用することもできます。右クリックは、Web サイトの特定の要素の左クリックとしてのみ機能するため、これは素晴らしいことです。そうすれば、ほとんどの場合、期待どおりにマウスを使用することができます (セレクターによって異なります)。
編集:より良い例
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#rightclick").bind('contextmenu', function(event) {
// on right click
if (event.which == 3)
{
// prevent right click from being interpreted by the browser:
event.preventDefault();
$(this).click(); // simulate left click
}
});
$('#rightclick').click(function() {
$(this).html("i have been clicked!");
});
});
</script>
</head>
<body>
<p>This is a web page.</p>
<div id="rightclick" style="width:200px; height:100px; background-color: orange">
Click me with the right or left mouse button. Both will work!
</div>
</body>
</html>