Thursday, September 18, 2008

How to disable right click (Context Menu) on object in browser

Example in picture object:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script language="javascript">
function disableContextMenu(obj) {
obj.oncontextmenu = function() {
return false;
}
}
function onLoad() {
disableContextMenu(document.getElementById("Pic1"));
}
</script>
</head>
<body onload="onLoad()">
<img id="Pic1" src="Pic1.jpg" alt="Picture" />
</body>
</html>

Or use this code:
<img id="Pic1" src="Pic1.jpg" alt="Picture" onmouseover="this.oncontextmenu=function(){return false}" />

Result:


No comments:

Post a Comment