如何使用 Javascript 从另一个选项卡刷新

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

How can I refresh a tab from another using Javascript

javascript

提问by xbonez

I'm looking to achieve something like Wordpress does when you create a new post. It allows you to preview your post by opening a new tab. If, after that, you edit the post and preview it again, rather than opening another tab, it refreshes the previously opened tab (provided it is still open).

我希望在您创建新帖子时实现类似 Wordpress 的功能。它允许您通过打开一个新标签来预览您的帖子。如果在那之后,您编辑帖子并再次预览它,而不是打开另一个选项卡,它会刷新之前打开的选项卡(前提是它仍然打开)。

From some research it seems I can open a new window and give it a name to identify it, like this:

从一些研究来看,我似乎可以打开一个新窗口并为其命名以识别它,如下所示:

window.open(url,"foobar");

window.open(url,"foobar");

But, how can I later refresh this tab? location.reload()does not seem to take a name as an argument.

但是,我以后如何刷新此选项卡?location.reload()似乎没有将名称作为参数。

回答by Aadit M Shah

If I remember correctly this is the way to do it:

如果我没记错的话,这是这样做的方法:

var win = window.open(url, "foobar");
win.location.reload();

回答by tzerb

I think you're looking for the property window.opener. See http://www.w3schools.com/jsref/prop_win_opener.asp

我认为您正在寻找属性 window.opener。见http://www.w3schools.com/jsref/prop_win_opener.asp

回答by srsajid

You can do this by "storage" event. for more details follow

您可以通过“存储”事件来做到这一点。更多详情请关注

Communication between tabs or windows

选项卡或窗口之间的通信

https://developer.mozilla.org/en-US/docs/Web/Events/storage

https://developer.mozilla.org/en-US/docs/Web/Events/storage