Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从父窗口刷新子窗口_Javascript - Fatal编程技术网

Javascript 从父窗口刷新子窗口

Javascript 从父窗口刷新子窗口,javascript,Javascript,使用JavaScript 我的父窗口中有“刷新”按钮 当我点击刷新按钮时 我想刷新我的子窗口 window.location.href='add\u billing\u order\u frm.php?session\u re\u genrate=new 此代码段重定向页面而不是刷新 我想有一个片段是这样的 opener.document.location.reload(true) 但这一个用于父窗口刷新,但我想用于具有URL位置选项的子窗口 function show_billing_orde

使用JavaScript

我的父窗口中有“刷新”按钮

当我点击刷新按钮时

我想刷新我的子窗口

window.location.href='add\u billing\u order\u frm.php?session\u re\u genrate=new

此代码段重定向页面而不是刷新

我想有一个片段是这样的

opener.document.location.reload(true)

但这一个用于父窗口刷新,但我想用于具有URL位置选项的子窗口

function show_billing_order_form(url){
   var childWindow = window.open(url);
}

function refresh_my_child_window(){
   return childWindow.location.reload('add_billing_order_frm.php');
}
为了打开一个弹出窗口(子窗口),我使用了这个show\u billing\u order\u form callback

为了刷新子窗口,我在父窗口中添加了一个刷新图标,为了刷新子窗口,在我称为“刷新我的子窗口”的刷新图标onclick中


但是函数刷新我的子窗口。

从父窗口打开子窗口时,请记住某个变量中的返回值:

var childWindow = window.open(/* ... */);
…当您要刷新子项时:

childWindow.location.reload();
请注意,如果未从中加载父项和子项,则某些浏览器将阻止访问
childWindow.location.reload

下面是一个简单的示例(-注意:live copy只在非编辑模式下工作,就像给定的链接一样,因为否则JSBin使用
null.JSBin.com
而不是
output.JSBin.com
,因此源代码不匹配):

HTML:


警告:我决不建议将事件处理程序与上面的
onclick
属性连接起来。相反,我会使用
addEventListener
(在基于标准的浏览器上)或
attachEvent
(在IE上),方法是使用库或类似的实用函数。使用上面的属性来避免混淆要点。

@PiyushBalapure-确实如此,只是JSBin从
http
切换到
https
,因此示例停止工作,因为父级打开了
https
,而子级打开时使用的是
http
。我已经更新了live example链接。
var childWindow = window.open("","name",/* .. */);
childWindow.location.reload();
(function() {
    var childWindow;

    document.getElementById('btnOpen').onclick = openChildWindow;
    document.getElementById('btnClose').onclick = closeChildWindow;
    document.getElementById('btnRefresh').onclick = refreshChildWindow;

    function openChildWindow() {
        if (childWindow) {
            alert("We already have one open.");
        } else {
            childWindow = window.open(location.protocol + "//" + location.host + "/cotokijigu/1");
        }
    }

    function closeChildWindow() {
        if (!childWindow) {
            alert("There is no child window open.");
        }
        else {
            childWindow.close();
            childWindow = undefined;
        }
    }

    function refreshChildWindow() {
        if (!childWindow) {
            alert("There is no child window open.");
        } else {
            childWindow.location.reload();
        }
    }
})();
var childWindow = window.open("","name",/* .. */);
childWindow.location.reload();