简体   繁体   English

对于IE和FF使用JQuery或onbeforeunload

[英]Use JQuery or onbeforeunload for IE and FF

I'm working in a Flex4 application, using javascript, in the "index.template.html" document. 我在“index.template.html”文档中使用javascript在Flex4应用程序中工作。 I'm having an issue being able to use onbeforeunload with Firefox. 我有一个问题是能够在Firefox上使用onbeforeunload。 The application works perfectly in IE, but the exact same one doesn't sit well with FF. 该应用程序在IE中完美运行,但完全相同的一个不适合FF。 (See below) (见下文)

<script type="text/javascript">
window.onbeforeunload=before;
window.onunload=after;

function before(evt)
{
   var flex=document.$(application)||window.$(application);
   flex.unloadMethod(); //custom method to log out the user
}

function after(evt)
{

}
</script>

From what I've found, FF doesn't seem to register onbeforeunload events, so I found that the popular thing to use instead is binding with JQuery. 从我发现的,FF似乎没有注册onbeforeunload事件,所以我发现使用的流行的东西是与JQuery绑定。 So, I deleted the above code and replaced it with the below code, but it doesn't display a pop-up when the user tries leaving the page in both IE and FF. 因此,我删除了上面的代码并将其替换为以下代码,但是当用户尝试在IE和FF中离开页面时,它不会显示弹出窗口。 Anyone that seems to be using JQuery for this seems to be doing the exact same thing, so I don't know what's going on. 任何似乎都在使用JQuery的人似乎都在做同样的事情,所以我不知道发生了什么。

<script type="text/javascript">
$(window).bind("beforeunload",function(event){
   return "This should create a pop-up";
});
</script>

Eventually it would be nice to call the "flex.unloadMethod" like in the first bit of code, but for the time being I'm just trying to get a pop-up to work so I know I'm on the right track. 最终在第一段代码中调用“flex.unloadMethod”会很好,但暂时我只是试图让弹出窗口工作,所以我知道我在正确的轨道上。 Any insight would be greatly appreciated. 任何见解将不胜感激。

Try: 尝试:

<script>
    $(window).on('beforeunload', function(){
        return "This should create a pop-up";
    });
</script>

Example: http://jsfiddle.net/AeztA/3/ 示例: http//jsfiddle.net/AeztA/3/

Would like to add that i figured out that you can't use an empty string in firefox. 想补充一点,我想你不能在firefox中使用空字符串。 It has to be at least 1 blank for example as return. 它必须至少为1个空白,例如作为返回。

var text = 'Exit Message';

$(window).on('beforeunload', function(){
    return " " + text;
});

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

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