简体   繁体   English

窗口打开时IE9触发onb​​eforeunload事件

[英]IE9 firing onbeforeunload event when the window opens

I'm building a site using the JFileUpload applet and want to handle the closing of a page in a certain way. 我正在使用JFileUpload小程序构建站点,并希望以某种方式处理页面的关闭。 JSTransferCancelled is called when the applet is cancelled. 取消小程序时,将调用JSTransferCancelled。 The following code is what I'm using to handle these events and it works in all browsers except IE. 以下代码是我用来处理这些事件的代码,它可用于除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();} 
        }); 
    });

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] 但是,当我在IE中打开标签页时,我立即收到警报,提示The webpage you are viewing is trying to close this tab. Do you want to close this tab? [OK] [Cancel] The webpage you are viewing is trying to close this tab. Do you want to close this tab? [OK] [Cancel] 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. The webpage you are viewing is trying to close this tab. Do you want to close this tab? [OK] [Cancel]和我的上载器都因为setEnabled(false)调用而无法访问,并且由于cancel()调用而被cancel()

What I'm looking for is the same functionality, just in IE. 我正在寻找的是相同的功能,只是在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. 我知道IE中的事件有很多很多问题,例如onbeforeunload,它会触发以响应不同的事物,但是我已经检查了我站点中的所有这些问题,但没有发现任何问题。 I haven't run into anything online that deals with the kind of problem I'm having. 我还没有在网上遇到任何可以解决我遇到的问题的东西。

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. 我曾尝试将onbeforeunload函数包装在不同的东西中,例如上面的load函数以及$(document).ready() ,但是它们给了我同样的问题,或者创建了新的问题。

查看Microsoft的荒谬文档,然后确保所使用的代码中没有任何代码可作为触发beforeunload的触发器列出来的beforeunload ,其中包括实际上并未卸载页面的几件事(去Microsoft!)

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

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