Javascript onbeforeunload不';在Visual Studio 2013中无法工作

Javascript onbeforeunload不';在Visual Studio 2013中无法工作,javascript,visual-studio-2013,onbeforeunload,browser-link,Javascript,Visual Studio 2013,Onbeforeunload,Browser Link,在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(wi

在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>

jQuery(window).bind('beforeunload',函数(e){
var message=“你为什么要离开?”;
e、 返回值=消息;
返回消息;
});
onbeforeunload
事件不会触发。但是,如果您使用Visual Studio 2012打开它,它将起作用(请注意,要使用Visual Studio 2012打开它,您不应使用
ASP.NET MVC 5
)。

正在替换原始的
onbeforeuload
事件。尽管这在其他浏览器中也会发生

如果您想在卸载之前使用
onbeforeunload
事件,您应该这样做