提示:文章寫完後,目錄可以自動生成,如何生成可參考右邊的幫助文檔
文章目錄
- 一、禁用右鍵
- 二、禁用ctrl+c,ctrl+v
- 三、禁止傳回上一頁
- 總結
一、禁用右鍵
代碼如下(示例):
// 右クリックを無効にする
document.body.onselectstart =
document.body.oncontextmenu =
function () {
// ブラウザのデフォルト操作をキャンセル
return false;
};
二、禁用ctrl+c,ctrl+v
代碼如下(示例):
window.onload = function(){
document.onkeydown = function(event){
if (event.ctrlKey && window.event.keyCode==67){
console.log("シールドctrl+c");
return false;
}
if (event.ctrlKey && window.event.keyCode==86){
console.log("シールドctrl+v");
return false;
}
}
}
三、禁止傳回上一頁
代碼如下(示例):
// 前のページに戻ることを禁止
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
});
}
if ('pushState' in history) {
window.history.pushState('forward', null, '#');
window.history.forward(1);
}else{
History.pushState('forward', null, '?state=2');
window.history.forward(1);
}
window.onhashchange=function(){
History.pushState('forward', null, '?state=1');
}