JavaScript的"beforeunload"事件在IE中不起作用 [英] JavaScript 'beforeunload' event not working in ie

查看:469
本文介绍了JavaScript的"beforeunload"事件在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开一个弹出窗口,然后在关闭弹出窗口后(刷新父页面)

I need to open a pop-out window, then after close pop-out window (refresh a parent page)

jquery'beforeunload'事件在Internet Explorer 8,9中不起作用.

jquery 'beforeunload' event not working in internet explorer 8,9.

我的代码是:

 /*
  * events
  * add tallyman
  */
 $("div.main form div.tallymanlist").click(function() {
     if(gencargo.show_confirm('Add  new tallyman?')) {
         var windowObject = gencargo.windowOpener(600,1400, "Tallyman",$(this).children().attr("url"));
         gencargo.windowParentRefresh(windowObject);
     }
 });

gencargo对象是内容(打开的窗口):

gencargo object is content (window open):

    /*
     *  open  window 
     */
    windowOpener : function (windowHeight, windowWidth, windowName, windowUri) {
        var centerWidth = (window.screen.width - windowWidth) / 2;
        var centerHeight = (window.screen.height - windowHeight) / 2;

        newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
            ',height=' + windowHeight + 
            ',left=' + centerWidth + 
            ',top=' + centerHeight);

        newWindow.focus();
        return newWindow;
    },

并关闭窗口:

    windowParentRefresh : function(object) {

      $(object).bind('beforeunload', function () {
            object.opener.location.reload();
      });
    }

关闭窗口事件在IE中不起作用.仅在FireFox,Chrome,Opera中.

Close window event is not working in ie. Only in FireFox, Chrome, Opera.

推荐答案

尝试以下方法:

 /*
  * reload page
 */
     windowParentRefresh: function(object) {

          setTimeout(function() {
              setTimeout(function() {
            $(object).bind('beforeunload', function() {
                object.opener.location.reload();
            });
              }, 1000);
          },1);

     }

这篇关于JavaScript的"beforeunload"事件在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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