1

I'm looking for a JavaScript alternative to onContextMenu in an xHTML page. I want to hide the menu which pops-up (The context menu) When I click the right mouse button on a website.

I have a problem using the onContextMenu attribute because it doesn't pass the validator for xHTML Strict.

4

1 回答 1

2

oncontextmenu如果您附加到外部脚本中,它将起作用:

<script type="text/javascript" src="script.js"></script>

(确保您包含该type属性,以便它验证。)

script.js

document.body.oncontextmenu = function handleContextMenu(e) {
  e.preventDefault();
  e.stopPropagation();
};
于 2013-03-02T17:56:58.083 回答