有的時候,我們不希望自己網頁中所呈現的內容不被別有用心盜取,就需要在網頁中加上一個禁止複製的功能,而一般的瀏覽器在禁止複製後還可以用複製爲純文本,並不能完全杜絕此問題,此時就需要我們在頁面中完全禁止右鍵和複製。
實現起來其實很簡單,只需要在網頁中加入以下標籤(注意是緊隨body後):
<body topmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
這只是一個最初步的方法,也很容易被人破解,怕網頁被別人另存爲本地文件,可以再加上以下代碼防止別人保存:
<noscript>
<iframe src="*.htm"></iframe>
</noscript>
最後,有的站長可能只需要一個禁止複製的功能,並不需要禁止右鍵,則在<body>中加入以下代碼即可:
<body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">