1

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

4

1 回答 1

1

浏览器链接(Visual Studio 2013 的新功能之一)正在替换原来的onbeforeunload事件。这里报告了 Firefox,尽管这也发生在其他浏览器中。

如果你想使用onbeforeunload事件,你应该禁用 Browser Link

于 2015-01-20T14:14:10.543 回答