从父页面重新加载一个子页面 [英] Reload a child page from parent page

查看:161
本文介绍了从父页面重新加载一个子页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了一个子页面(从父页面的链接打开),每次从父页面重新加载子页面。但这在我刷新父页面时不起作用。

 < li>< a href =js。 phptitle =alert-tabonclick =myWindow = window.open('http://www.google.com','_blank');>新窗口< / a>< / li> 

< li>< a href =#title =alert-tabonclick =myWindow.location.reload();>重新加载< / a>< / li> ;

在这个问题上的任何帮助?

htt: //google.com ,假设你不是Google编码器)。



所以你不能这样做,除非远程服务器授权,这是不经常的。





 < li>< a href =#如果页面位于同一个域中, title =alert-tabonclick =myWindow = window.open('index2.html','_ blank');>新窗口< / a>< / li> 
< li>< a href =#title =alert-tabonclick =myWindow.location.reload();>重新加载< / a>< / li>

请小心测试,以便始终在 http://
$ b>(而不是 file:// ),因为2个本地文件始终被视为单独的域。

请注意,如果您给窗口一个名称,下次它将被加载时将会在同一个窗口中,即使您重新加载了父页面之间:

 < li>< a href =#title =alert-tabonclick =myWindow = window.open('index2.html','someName');> ;新窗口< / a>< / li> 

因此,如果您希望在重新加载父页面时重新加载子页面,则可以执行像这样:

 < li>< a href =#title =alert-tabid = mylink> ;新窗口< / a>< / li> 
< script>
函数openPage(){
myWindow = window.open('index2.html','someName');
localStorage ['open'] ='是';
}
window.onload = function(){
document.getElementById('mylink')。onclick = openPage;
if(localStorage ['open'] =='yes')myWindow = window.open('index2.html','someName');
localStorage ['open'] ='no';
};
< / script>

这个想法是在加载时检查子窗口是否上次打开,如果需要的话强制重新加载。



当然,这只适用于父母和子女由同一个域提供服务。


I want a child page(that is opened from a link of parent page) will be reloaded every time from parent page when i click the Reload.

I used this but this don't work when i refresh the parent page.

<li><a href="js.php" title="alert-tab"  onclick="myWindow=window.open('http://www.google.com','_blank');">New Window</a></li>

<li><a href="#" title="alert-tab"  onclick="myWindow.location.reload();">Reload</a></li>

Any help on this issue?

解决方案

For security reason you can't read or change (including reload) in modern browsers a window/iframe that was loaded with the URL of another domain (like htt://google.com, supposing you're not a Google coder).

So you can't do that except if the distant server authorized it, which isn't frequent.

If the page is on the same domain, this works :

<li><a href="#" title="alert-tab"  onclick="myWindow=window.open('index2.html','_blank');">New Window</a></li>
<li><a href="#" title="alert-tab"  onclick="myWindow.location.reload();">Reload</a></li>​

Be careful in your tests to always open in http:// (and not file://) as 2 local files are always considered as separate domains.

Note that if you give a name to your window, the next time it will be loaded will be in the same window, even if you reloaded the parent page in between :

<li><a href="#" title="alert-tab"  onclick="myWindow=window.open('index2.html','someName');">New Window</a></li>

So, if you want to have the child page reloaded when you reload the parent page, you could do something like this :

<li><a href="#" title="alert-tab" id=mylink>New Window</a></li>
<script>
function openPage(){
    myWindow=window.open('index2.html','someName');
    localStorage['open'] = 'yes';
}
window.onload = function(){
    document.getElementById('mylink').onclick=openPage;
    if (localStorage['open']=='yes')  myWindow=window.open('index2.html','someName');
    localStorage['open'] = 'no';
};
</script>

The idea is to check at loading if the child window was open last time and if necessary force its reload.

Of course, this works only if parent and child are served from the same domain.

这篇关于从父页面重新加载一个子页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆