简体   繁体   English

onbeforeunload在Visual Studio 2013中不起作用

[英]onbeforeunload doesn't work from Visual Studio 2013

Create a web project in Visual Studio 2013, remove all scripts (which could interfere) and add this: 在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>

The onbeforeunload event won't fire. onbeforeunload事件不会触发。 However if you open this with Visual Studio 2012 it will work (note that to open it with Visual Studio 2012 you shouldn't use ASP.NET MVC 5 ). 但是,如果使用Visual Studio 2012打开它,它将起作用(请注意,如果要使用Visual Studio 2012打开它,则不应使用ASP.NET MVC 5 )。

Browser Link (one of the new features of Visual Studio 2013) is replacing the original onbeforeunload event. 浏览器链接(Visual Studio 2013的新功能之一)将替换原始的onbeforeunload事件。 Here this is reported for Firefox although this also happens in other browsers. 尽管在其他浏览器中也会发生这种情况,但此处报告的是Firefox

If you want to work with onbeforeunload event you should disable Browser Link . 如果要使用onbeforeunload事件,则应禁用Browser Link

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM