Html頁面中內容禁止選擇、複製、右鍵的實現方法

有的時候,我們不希望自己網頁中所呈現的內容不被別有用心盜取,就需要在網頁中加上一個禁止複製的功能,而一般的瀏覽器在禁止複製後還可以用複製爲純文本,並不能完全杜絕此問題,此時就需要我們在頁面中完全禁止右鍵和複製。

clipboard.png
實現起來其實很簡單,只需要在網頁中加入以下標籤(注意是緊隨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()">  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章