【问题标题】:onbeforeunload doesn't work from Visual Studio 2013onbeforeunload 在 Visual Studio 2013 中不起作用
【发布时间】:2015-01-20 14:14:10
【问题描述】:

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

【问题讨论】:

    标签: javascript visual-studio-2013 onbeforeunload browser-link


    【解决方案1】:

    Browser Link (one of the new features of Visual Studio 2013) 正在替换原来的 onbeforeunload 事件。 Here this is reported for Firefox 虽然这也发生在其他浏览器中。

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

    【讨论】:

      猜你喜欢
      • 2015-07-28
      • 1970-01-01
      • 2014-10-10
      • 2014-06-18
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      相关资源
      最近更新 更多