在網上找尋資料時,會遇到個別網頁禁止了鼠標右鍵以及復制功能,使得無法直接的將資料信息復制下來。我便查了一下解決的辦法,記錄下個人認為比較簡單的一個方法,下面便是代碼:
document.oncontextmenu = function (){return true;}
document.onselectstart = function (){return true;}
document.onsdragstart = function (){return true;}
document.body.onmouseup = function (){}
document.body.oncopy = function (){}
document.body.onbeforecopy = function (){}
document.onmousedown = function (){}
將以上代碼復制,然后在對應頁面的控制臺(F12)中, 輸入并執行即可。之后就會發現,右鍵、復制都OK了。
如果有更好的方法歡迎分享出來。