javascript top.opener.location.reload(true) 不刷新 IE 上的父页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3753594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
top.opener.location.reload(true) not refreshing parent page on IE
提问by Erez
I have two pages, the parent and from this page I am using:
我有两个页面,父页面和我正在使用的这个页面:
window.open('OrderDetailsFull.aspx?ObjectID=' + ObjectID[1] , "TableDetails","status=0 , toolbar=0 , location=no , menubar=0 , scrollbars=yes , height=600px , width=800px");
to open a new window and manipulate data over there.
打开一个新窗口并在那里操作数据。
When I finish what I am doing I need the parent page to refresh so I will get the new data data in it...
当我完成我正在做的事情时,我需要刷新父页面,这样我才能在其中获取新的数据数据...
From what I know the method is:
据我所知,方法是:
top.opener.location.reload(true);
but for some reason, it is not working in IE8 or IE9...
但由于某种原因,它在 IE8 或 IE9 中不起作用......
As I am building an application and not a general web page. It will work on Windows OS with IE (as for now it is still the most common system...nothing to do about it) so I really need to solve this problem....
因为我正在构建一个应用程序而不是一个通用的网页。它将在带有 IE 的 Windows 操作系统上运行(至于现在它仍然是最常见的系统......无事可做)所以我真的需要解决这个问题......
I couldn't find any new solution over the web for this problem, every one say it should work like that.....
对于这个问题,我在网上找不到任何新的解决方案,每个人都说它应该像那样工作......
Did anyone encounter this problem? and does any one knows how to solve it?
有没有人遇到过这个问题?有谁知道如何解决它?
OK, FOLLOW UP question: when I do opener.location.reload(true);does it render the parent page all over again (as it sound) or not? If it does then I'm in a big problem, if not, then there must be a way to do that...
好的,跟进问题:当我这样做时opener.location.reload(true);,它是否会再次呈现父页面(听起来)?如果是这样,那么我遇到了大问题,如果不是,那么必须有办法做到这一点......
The problem is the I have an ajax call in the parent page and for some reason it stays in it's old values when I am using it, only when I reload the child window, the parent ajax shows the real results, some code follows...
问题是我在父页面中有一个ajax调用,并且由于某种原因它在我使用它时保持旧值,只有当我重新加载子窗口时,父ajax才会显示真实结果,一些代码如下.. .
This is in the document ready jQuery function of the opener page:
这是在打开页面的文档就绪 jQuery 函数中:
$('div[id^="divTable"]').hover(
function(e){
//???? ???? ?????? ?????
ObjectID = $(this).attr('id').split('_');
$(this).css("cursor","pointer");
//AJAX ???? ????? ????? ?????? ????? ?
var OrderDetails = $.ajax({
url:'AjaxActions/OrderDetails.aspx?ObjectID=' + ObjectID[1],
async:false
}).responseText;
//?? ??? ????? ???????? ????, ???? ????? ?? ???? ?????? ?? ???? ?????? DIV
$(this).append($('<div style="position: absolute; top: 0; left: -150;">' + OrderDetails + '</div>'));
//????? ??????? ???? ??? ?????? ???? ??????
$(this).css("z-index","10");
$(this).siblings().css("z-index","1");
},
//???????? ??????? DIV????? ?
function () {
$(this).find('div:last').remove()
}
);
This is in one of the functions in the child window that should refresh the opener:
这是子窗口中应该刷新开启器的功能之一:
$('#ctrl_Print').click(
function()
{
alert($('#hidItem').val());
var Items = new Array();
Items = $('#hidItem').val().split(',');
for(var i=0;i<Items.length;i++)
{
alert(Items[i]);
}
opener.location.reload(true);
window.location = 'OrderDetailsFull.aspx?OrderID=' + OrderID + '&ObjectID=' + ObjectID + '&Print=' + Items;
window.close();
}
);
10x...
10倍...
回答by anoopjohn
It looks like IE 8 and 9 have security restrictions on refreshing the opener.
看起来 IE 8 和 9 对刷新开启器有安全限制。
回答by Micah Fletcher
I've run into this problem where reload() works in Chrome, but pukes in IE.
我遇到了这个问题,reload() 在 Chrome 中工作,但在 IE 中呕吐。
Try using window.location.replace(your url and params here).
尝试使用 window.location.replace(您的网址和参数在这里)。
You have to collect the url and params for replace(), but it gets around the IE error message.
您必须为 replace() 收集 url 和 params,但它绕过了 IE 错误消息。
Example:
例子:
In Joomla 2.5 parent window launches modal for users input, where we need to reload the parent window (view) in order to run code that uses modal input.
在 Joomla 2.5 中,父窗口为用户输入启动模态,我们需要重新加载父窗口(视图)以运行使用模态输入的代码。
The modal fires a function in the parent window like;
模态在父窗口中触发一个函数,例如;
function updateAddresses(runUpdate, itemID, closeModal){
if(closeModal == true ){
SqueezeBox.close();
}
if(runUpdate == true){
//location.reload();
var replaceURL = 'index.php?option=com_poecom&view=cart&ItemId='+itemID;
window.location.replace(replaceURL);
}
}
回答by Lekensteyn
If you want to access the parent window (or frame), you should use parent, not top:
如果要访问父窗口(或框架),则应使用parent,而不是top:
parent.location.reload(true);
When your page is a frame inside that window, add more parents to it:
当您的页面是该窗口内的框架时,向其添加更多parents:
parent.parent.location.reload(true);
回答by Tim Down
topis used to get the outermost document within the current physical window when you're dealing with framesets and/or iframes and is not related to window.openin any way, so you shouldn't use topunless there are frames or iframes within your pop-up page. The following will do:
top用于在处理框架集和/或 iframe 时获取当前物理窗口中最外层的文档,并且不以window.open任何方式与之相关,因此top除非弹出页面中有框架或 iframe,否则不应使用. 将执行以下操作:
opener.location.reload(true);

