小夥伴們在開發的時候偶爾會遇到這樣的需求,客戶要求文章頁禁止複製和粘貼,實現這個功能代碼如下 (可同時實現PC端和手機端):
*{
-webkit-touch-callout:none; /*系統默認菜單被禁用*/
-webkit-user-select:none; /*webkit瀏覽器*/
-khtml-user-select:none; /*早期瀏覽器*/
-moz-user-select:none;/*火狐*/
-ms-user-select:none; /*IE10*/
user-select:none;
}
在添加完這段代碼後,在IOS 上會有問題的,這個時候你會發現input 框無法正在輸入了內容了;造成這個原因就是 -webkit-user-select:none; 這個屬性造成的。
解決這個方法 就是 在css 文件中同時設置一下input 的屬性,如下所示:
input {
-webkit-user-select:auto; /*webkit瀏覽器*/
}