窗口打开时IE9触发onb​​eforeunload事件 [英] IE9 firing onbeforeunload event when the window opens

查看:89
本文介绍了窗口打开时IE9触发onb​​eforeunload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JFileUpload 小程序构建站点,并希望处理某些页面的关闭方法.取消小程序时,将调用JSTransferCancelled.以下代码是我用来处理这些事件的代码,它可在除IE之外的所有浏览器中使用.

I'm building a site using the JFileUpload applet and want to handle the closing of a page in a certain way. JSTransferCancelled is called when the applet is cancelled. The following code is what I'm using to handle these events and it works in all browsers except IE.

        function JSTransferCancelled(){
            bCancel=false;
            $.post("cancel.php");
            self.close();
        }

    $(window).load(function(){

        $(window).bind('beforeunload',function(){
            document.uploader.setEnabled(false);
            if(bCancel){ document.uploader.cancel();} 
        }); 
    });

我在主网站的新标签页中打开了带有上传器的页面,并希望在他们取消上传时将其关闭.但是,当我在IE中打开选项卡时,我立即收到警报,提示The webpage you are viewing is trying to close this tab. Do you want to close this tab? [OK] [Cancel],并且由于setEnabled(false)调用而无法访问我的上传器,并且由于cancel()调用而取消了上传器.

I open the page with the uploader on it in a new tab from the main site and want to close it when they cancel the upload. When I open the tab in IE, however, I instantly get the alert saying The webpage you are viewing is trying to close this tab. Do you want to close this tab? [OK] [Cancel] and my uploader is both inaccessible because of the setEnabled(false) call and cancelled because of the cancel() call.

我正在寻找的是相同的功能,只是在IE中.我知道IE中有很多很多问题,其中包括onbeforeunload之类的事件,它会触发以响应不同的事物,但是我已经检查了我站点中的所有这些问题,但没有发现任何问题.我还没有在网上遇到任何可以解决我所遇到的问题的东西.

What I'm looking for is the same functionality, just in IE. I know there are many many many issues in IE with events like onbeforeunload with it triggering in response to different things, but I've checked for all of those problems in my site and haven't found anything. I haven't run into anything online that deals with the kind of problem I'm having.

我曾尝试将onbeforeunload函数包装在不同的东西中,例如上面的load函数以及$(document).ready(),但是它们要么给我带来相同的问题,要么创建新的问题.

I've tried wrapping the onbeforeunload function in different things such as the load function above as well as $(document).ready(), but they either give me the same problems or create new ones.

推荐答案

检查

Check Microsoft's Ridiculous Documentation Then make sure none of the code you are using does anything they list as a trigger to invoke beforeunload, which includes several things that do not actually unload the page (go Microsoft!)

这篇关于窗口打开时IE9触发onb​​eforeunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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