JS中实现网页中禁止下载图片
我把这个网页的代码由贴出来:
<html>
<head>
<title> fdsafdsafsda</title>
<script language="javascript">
<!--
function MM()
{
if(event.srcElement.id=='an') //判断右击事件发生在哪个对像上面
{
alert("对不起,本图片不能复制,版权所有!")
document.oncontextmenu=new Function("event.returnValue=false;"); //禁用右键功能
}
else
{
document.oncontextmenu=new Function("event.returnValue=true;"); //启用右键功能
}
}
-->
</script>
</head>
<body oncontextmenu="MM()">
<p><center><img id="an" src="Wallpaper/2_12011134O.jpg"/ width="250px" height="160px"></center> </p>
</body>
</html>
<head>
<title> fdsafdsafsda</title>
<script language="javascript">
<!--
function MM()
{
if(event.srcElement.id=='an') //判断右击事件发生在哪个对像上面
{
alert("对不起,本图片不能复制,版权所有!")
document.oncontextmenu=new Function("event.returnValue=false;"); //禁用右键功能
}
else
{
document.oncontextmenu=new Function("event.returnValue=true;"); //启用右键功能
}
}
-->
</script>
</head>
<body oncontextmenu="MM()">
<p><center><img id="an" src="Wallpaper/2_12011134O.jpg"/ width="250px" height="160px"></center> </p>
</body>
</html>