从父窗口刷新子窗口 [英] refresh child window from parent window
问题描述
使用JavaScript
Using JavaScript
我的父窗口中有刷新按钮,
i have the refresh button in my parent window,
当我点击刷新按钮时,
我想刷新我的子窗口,
window.location。 href ='add_billing_order_frm.php?session_re_genrate = new
window.location.href='add_billing_order_frm.php?session_re_genrate=new
此代码段重定向页面而不是刷新,
This snippet redirecting the page instead refresh ,
我的东西有一个类似的片段
I thing there is a snippet like
opener.document.location.reload(true);
opener.document.location.reload(true);
但是这一个用于父窗口刷新,但我希望子窗口与URL位置选项
but this one for parent window refresh, but i want for child window wiht URL location option
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_billing_order_form回调,
To open a popup window(child window) , i used this show_billing_order_form call back ,
要刷新子窗口,我在父窗口中添加一个刷新图标,刷新子窗口,在该刷新图标上点击我名为refresh_my_child_window,
To refresh the child window , i add one refresh icon in my parent window , To refresh the child window , in that refresh icon onclick i called refresh_my_child_window ,
但功能刷新我的子窗口..
but function refreshing my child window..
推荐答案
打开子窗口时从父节点开始,记住某个变量中的返回值:
When opening your child window from the parent, remember the return value in a variable somewhere:
var childWindow = window.open(/* ... */);
...当你想刷新孩子时:
...and when you want to refresh the child:
childWindow.location.reload();
请注意,某些浏览器会阻止访问 childWindow.location.reload
如果未从同一来源加载父级和子级。
Note that some browsers will prevent access to childWindow.location.reload
if the parent and child aren't loaded from the same origin.
这是一个快速而肮脏的例子(直播复制 —注意:实时副本仅在非编辑模式下工作,如给定的链接,因为否则JSBin使用 null.jsbin.com
代替 output.jsbin.com
,因此原点不匹配):
Here's a quick-and-dirty example (live copy — note: the live copy only works in non-edit mode, like the link given, because otherwise JSBin uses null.jsbin.com
instead of output.jsbin.com
and so the origin doesn't match):
HTML:
<input type='button' id='btnOpen' value='Open Child'>
<input type='button' id='btnClose' value='Close Child'>
<input type='button' id='btnRefresh' value='Refresh Child'>
JavaScript:
JavaScript:
(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();
}
}
})();
警告:我绝不会建议用<$ c挂钩事件处理程序$ c> onclick 上面的属性。相反,我使用 addEventListener
(在基于标准的浏览器上)或 attachEvent
(在IE上),使用库或实用程序功能,如这一个。使用上面的属性来避免模糊主要点。
Caveat: I would never recommend hooking up event handlers with onclick
properties as above. Instead, I'd use addEventListener
(on standards-based browsers) or attachEvent
(on IE), by using a library or a utility function like this one. Used the properties above to avoid obscuring the main point.
这篇关于从父窗口刷新子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!