首页 新闻 赞助 找找看

js关闭子窗口刷新父窗口

0
悬赏园豆:5 [已解决问题] 解决于 2016-04-05 17:57

现在有两个窗口(A:显示发布的信息,B:发布信息页面)
我从窗口A点击发布到窗口B(用的是window.open方式打开),B上传成功后,我关闭B了,但是A没有刷新,我最新发布那条没有显示,我有上传成功后返回的状态值,现在想上传成功之后刷新窗口A,然后关闭当前窗口,但是现在卡在不知道该如何让窗口A刷新!请指点一下


-JackoChan的主页 -JackoChan | 初学一级 | 园豆:162
提问于:2016-03-03 21:40
< >
分享
最佳答案
0

在B中通过window.opener获取A

收获园豆:5
jello chen | 大侠五级 |园豆:7306 | 2016-03-03 22:06

window.opener.location.href=window.opener.location.href;       是这样写吗

-JackoChan | 园豆:162 (初学一级) | 2016-03-03 23:18

@ChEn嘉豪: 这是干啥

jello chen | 园豆:7306 (大侠五级) | 2016-03-03 23:21

@jello chen: 怎么获取呢,能写个大概出来看看吗?

-JackoChan | 园豆:162 (初学一级) | 2016-03-03 23:26

@ChEn嘉豪: 比如A.html:

<input type="button" value="Click Me" id="btn" />
    <script type="text/javascript">
        window.onload = function() {
            var btn = document.getElementById("btn");
            btn.onclick = function() {
                window.open("HtmlPage2.html", "new window", "width=200,height=100");
            }
        }

        function changeBtnValue(p) {
            var btn = document.getElementById("btn");
            btn.value = p;
        }
    </script>

B.html:

<input type="button" value="Change" id="btn"/>
<script type="text/javascript">
    window.onload = function () {
        var btn = document.getElementById("btn");
        btn.onclick = function () {
            window.opener.changeBtnValue("fuck");
        }
    }
</script>

这是你就可以在B中修改A中Button的Value了

jello chen | 园豆:7306 (大侠五级) | 2016-03-03 23:58

@jello chen: 是不是同理我可以在A窗口里面写个刷新页面方法,在B窗口调用A方法

-JackoChan | 园豆:162 (初学一级) | 2016-03-04 00:02

@ChEn嘉豪: 是的

jello chen | 园豆:7306 (大侠五级) | 2016-03-04 08:42

@jello chen: cannot call method 'reload' of null at xxx.html     返回上述的错误,空方法

-JackoChan | 园豆:162 (初学一级) | 2016-03-15 11:34

@ChEn嘉豪: 你可以将我上面贴出来的copy到html页面测试下

jello chen | 园豆:7306 (大侠五级) | 2016-03-15 11:37
其他回答(3)
0

window.opener 正解

龍☆ | 园豆:250 (菜鸟二级) | 2016-03-04 14:47
0

 子窗口关闭时 利用 $.pm 发送消息,父窗口监听,并处理

代码如下:view b

// 你的代码
// .......
//

// 关闭窗口之前操作
$.pm({
    target: window.opener,
    type: 'PaymentMethodDetailsResult',
    data: true
});

window.close();

 

view a

// 监听子窗口消息
$.YzMessage('PaymentMethodDetailsResult', function (result)
{
    if (result)
        grid.load();
});

 

$.YzMessage 代码:

; (function ($)
{
    $.extend({
        YzMessage: function (type, callback)
        {
            $(window).off('message.' + type + '.YzMessage').on('message.' + type + '.YzMessage', function (m)
            {
                var _data = eval('(' + m.originalEvent.data + ')');
                if (_data.type == type) {
                    callback.call($, _data.data);
                }
            });
        }
    });
})(jQuery);

 

$.pm 

https://github.com/Y2zz/postmessage

Y2zz | 园豆:393 (菜鸟二级) | 2016-03-04 16:24
0

window.opener.location.href = 'a窗口路径?'+ 加需要的参数  

其他属性都是不能获取

子窗口能做的是重新指定母窗口路径 母窗口刷新的时候 根据链接参数判断做什么操作

sw00 | 园豆:202 (菜鸟二级) | 2016-03-23 16:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册