今天搜索一些資料,碰到一些網站不能複製文本,
起初以爲是js限制問題,使用解除右鍵的js之後還是不行,
【資料:】
JS禁止選中文本方法
複製代碼
if (typeof(element.onselectstart) != "undefined") {
// IE下禁止元素被選取
element.onselectstart = new Function("return false");
} else {
// firefox下禁止元素被選取的變通辦法
element.onmousedown = new Function("return false");
element.onmouseup = new Function("return true");
}
複製代碼
IE下有onselectstart這個方法,通過設置這個方法可以禁止元素文本被選取。而firefox下沒有這個方法,但可以通過css或一種變通的辦法解決:
使用CSS:
div {
-moz-user-select:none;
-webkit-user-select:none;
user-select:none;
}
另外一種方法是:
ie:document.selection.empty()
ff:window.getSelection().removeAllRanges()
兼容的寫法:
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
這種方法不但不影響拖放對象的選擇效果,還能對整個文檔進行清除.
來源:https://www.cnblogs.com/pigtail/archive/2012/09/11/2680462.html
搜索相關js:
不是這裏控制,
搜索css:
右鍵在source panel打開,
.single-article {/*不允許選中文本*/-webkit-user-select:none;-moz-user-select:none;-o-user-select:none;-ms-user-select:none;user-select:none;}
.single-article pre {color:#dcdcdc;background:scroll #202020;border:1px dashed #ddd;display:block;/*代碼塊允許選中文本*/user-select:text;-webkit-user-select:text;-moz-user-select:text;-o-user-select:text;-ms-user-select:text;}
刪除相關代碼Ctrl+S保存即可解除
又可以愉快的複製文本了。