对于IE和FF使用JQuery或onbeforeunload [英] Use JQuery or onbeforeunload for IE and FF

查看:86
本文介绍了对于IE和FF使用JQuery或onbeforeunload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript在index.template.html文档中使用Flex4应用程序。我有一个问题是能够在Firefox上使用onbeforeunload。该应用程序在IE中完美运行,但完全相同的一个不适合FF。 (见下文)

I'm working in a Flex4 application, using javascript, in the "index.template.html" document. I'm having an issue being able to use onbeforeunload with Firefox. The application works perfectly in IE, but the exact same one doesn't sit well with 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>

从我发现的,FF似乎没有注册onbeforeunload事件,所以我发现相反,流行的东西是与JQuery绑定。因此,我删除了上面的代码并将其替换为以下代码,但是当用户尝试在IE和FF中离开页面时,它不会显示弹出窗口。任何似乎都在使用JQuery的人似乎都在做同样的事情,所以我不知道发生了什么。

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

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

最后在第一段代码中调用flex.unloadMethod会很好但暂时我只是试图让弹出工作,所以我知道我走在正确的轨道上。任何见解将不胜感激。

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. Any insight would be greatly appreciated.

推荐答案

尝试:

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

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

这篇关于对于IE和FF使用JQuery或onbeforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆