Html Javascript:无需完全重新加载即可刷新父页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15897434/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:22:14  来源:igfitidea点击:

Javascript: Refresh parent page without entirely reloading

javascripthtml

提问by Alasdair

After a user has logged in via a fancybox (javascript) popup I wish to reload the parent page so they can access the logged in features.

用户通过fancybox(javascript)弹出窗口登录后,我希望重新加载父页面,以便他们可以访问登录的功能。

Currently I am doing this with:

目前我正在这样做:

<a href="javascript:window.top.location.reload(true)" class="continue">Continue</a>

This works great, but the only issue is that it completely reloads the entire page: redownloads all the css & javascipt, etc.

这很好用,但唯一的问题是它会完全重新加载整个页面:重新下载所有 css 和 javascipt 等。

All I want to do is reload the page normally, not a full refresh. How can I achieve this?

我想要做的就是正常重新加载页面,而不是完全刷新。我怎样才能做到这一点?

(I do not know the exact URL because the login can be done from any page via the fancybox, so I can't hardcode the URL.)

(我不知道确切的 URL,因为可以通过fancybox 从任何页面进行登录,因此我无法对 URL 进行硬编码。)

回答by decden

Another way of reloading the page i have seen in the facebook graph apiis the following:

重新加载我在facebook graph api 中看到的页面的另一种方法如下:

window.location = window.location

or in your case:

或者在你的情况下:

window.top.location = window.top.location

This solution reloads the page without trying to resend a POSTrequest. Might be useful. for more information look at the following SO question.

此解决方案会重新加载页面,而不会尝试重新发送POST请求。可能有用。有关更多信息,请查看以下SO 问题

回答by Frédéric

Use:

用:

location.replace(location.href.split('#')[0]);

The spliton hash is required, otherwise an url with a hash will not be refreshed.

split散列是必需的,否则以散列的网址将不被刷新。

If you want to keep the previous load in browser history, use assigninstead of replace.

如果要在浏览器历史记录中保留以前的加载,请使用assign代替replace

hrefis not currently supported by Opera, according to MDN.

hrefMDN 称,Opera 目前不支持。