Visual Studio 2013 で Web プロジェクトを作成し、(干渉する可能性のある) すべてのスクリプトを削除して、これを追加します。
<script type="text/javascript" src="~/Scripts/jquery-1.8.2.min.js"></script> <!-- Note that the version might be different -->
<script type="text/javascript">
jQuery(window).bind('beforeunload', function (e) {
var message = "Why are you leaving?";
e.returnValue = message;
return message;
});
</script>
イベントはonbeforeunload
発生しません。ただし、これを Visual Studio 2012 で開くと機能します (Visual Studio 2012 で開く場合は を使用しないでくださいASP.NET MVC 5
)。