網(wǎng)絡(luò)上看到好的文章或者圖片,直接右鍵另存為就可以,但是一些好的文章或圖片不希望別人下載,怎么辦?那就要禁止在網(wǎng)站右鍵另存,想要實現(xiàn)這種功能,只需要簡單的JS代碼即可。
<script language="JavaScript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP)
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false
return false
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false
return false
}
}
document.oncontextmenu = nocontextmenu // for IE5+
document.onmousedown = norightclick // for all others
//-->
</script>
如何在頁面上禁止鼠標右鍵,希望能與大家多多交流,謝謝!