前提・実現したいこと
https://qiita.com/szaizen/items/91e652392825b90ef14a
こちらのサイトを参考に、ブラウザバックボタンの無効を実装しました。
しかし、eclipse・Edge・IEでは問題なく動作するのに、chromeではブラウザバック無効が機能しません。
キャッシュの削除やシークレットウィンドウなど試してみましたがうまくいきませんでした。
何が原因なのでしょうか。
該当のソースコード
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>テスト</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script> <style> .title{ text-align:center; } </style> <script> $(function(){ history.pushState(null, null, null); //ブラウザバック無効化 //ブラウザバックボタン押下時 $(window).on("popstate", function (event) { history.pushState(null, null, null); window.alert('このページでブラウザバックすることは出来ません'); }); }); </script> </head> <body> <h1 class="title" >テスト</h1> </body> </html>回答1件
あなたの回答
tips
プレビュー