h5設定網頁不能選中,複製等操作,防被趴!
阿新 • • 發佈:2018-12-14
最近在寫頁面的時候,需要在左上角加一個logo,但是複製的時候會把這張圖片一塊選中。
那麼我們可以通過CSS給它設定禁止選中,程式碼如下:
.icon { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Chrome/Safari/Opera */ -khtml-user-select: none; /* Konqueror */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none; /* Non-prefixed version, currently not supported by any browser */ }
新增禁止程式碼後,該圖片就不能被選中了。
HTML頁面內容禁止選擇、複製、右鍵
剛才在一個站點的原始碼的的時候發現的,其實原來真的很簡單
<body leftmargin=0 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()'>
關鍵就在
oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'
一個更簡單的方法就是在<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()"
1、禁止網頁另存為:在<body>後面加入以下程式碼:
<noscript> <iframe src="*.htm"></iframe> </noscript>
2、禁止網頁內容複製.貼上:在<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()">