代码改变世界

关闭子页面后,刷新父页面学习

2011-05-24 13:38  温森特  阅读(2398)  评论(0编辑  收藏  举报
关闭子页面后,刷新父页面,这个功能大家经常会需要用到。前两天写个项目用到这个功能,在这里记录一下,备以后使用。其实很简单,父窗口要用只需用简单的window。open函数就可以。
function OpenExcluded() {
              var left = (screen.width / 2) - 370;
              var top = (screen.height / 2) - 240;
              var targetWin = window.open('ExcludedStores.aspx', 'ExcludedStores', 'width=740,height=480,top=' + top + ',left=' + left + ',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');

          }    

玄机都在子页面,在子页面关闭的时候,通过opener 对象获取父页面控件,然后模拟父页面刷新按钮,即调用该控件的click()事件。

       function MyClose(message) {
            if (message != '') {
                window.alert(message);
                var btn = opener.document.getElementById('ctl00_ContentPlaceHolder1_btnSearch');
                btn.click();
            }
            window.close();
            

        }