1. 程式人生 > >html中禁止文字的複製

html中禁止文字的複製

直接在body標籤中寫入如下程式碼,即可實現在html中禁止文字的複製:

<body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
其中各個事件的意義是:
1)、oncontextmenu:單禁用右鍵選單
oncontextmenu='return false':來取消滑鼠右鍵
2)、ondragstart:事件在使用者開始拖動元素或選擇的文字時觸發 return false:禁止滑鼠在網頁上拖動
3)、onselectstart="return false" 禁止選中網頁上的內容

4)、onselect:事件會在文字框中的文字被選中時發生。 onselect="SomeJavaScriptCode" ,必需規定該事件發生時執行的 JavaScript。 document.selection.empty():表示文字框被選中時為空
5)、oncopy="return false" 防複製使用者在網頁上選中的內容
6)、onbeforecopy():預設動作的事件源物件上被取消。
7)、onmouseup:事件會在滑鼠按鍵被鬆開時發生。 onmouseup="SomeJavaScriptCode",同onselect一樣,必需規定該事件發生時執行的 JavaScript。
document.selection.empty():表示文字框被選中時為空

 

oncut="return false;" 防止剪下

onpaste="return false" 不準貼上



可以將這些程式碼貼上試試。