IE9 firing onbeforeunload event when the window opens

岁酱吖の 提交于 2020-01-03 03:29:24

问题


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();} 
        }); 
    });

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.

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.

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.


回答1:


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!)



来源:https://stackoverflow.com/questions/11549856/ie9-firing-onbeforeunload-event-when-the-window-opens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!