■ サンプル
<!DOCTYPE html> <html lang="ja"> <head> <title>Hello World</title> </head> <body> <div> <a href="index.html">link</a> </div> <form action="index.html" method="post"> <div> <input type="submit" id="button" value="ClickMe"> </div> </form> <script type="text/javascript"> window.onload = function() { // 本来は初期化処理を入れる } window.addEventListener('beforeunload', function(event) { // 本来は判定処理を入れる event.returnValue = "移動しますか?"; }); </script> </body> </html>
参考文献
http://blog.yuhiisk.com/archive/2016/02/02/alert-with-onbeforeunload.htmlhttps://donow.jp/skillup/?p=3271