12

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).

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");

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

Ayush
  • 41,754
  • 51
  • 164
  • 239

3 Answers3

18

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

var win = window.open(url, "foobar");
win.location.reload();
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
  • In this case, I don't **have** to give it a name, since I'm assigning it to a variable anyways, right? I could just do `var win = window.open(url);` – Ayush May 19 '12 at 03:49
  • 2
    @xbonez - But if you want to set its width and height and that kind of things, you'll have to. `window.open(url,"name","width=500,height=500");` – Derek 朕會功夫 May 19 '12 at 04:29
  • thanks. this helped me. just on more question, how do I switch to that tab? The page gets reloaded, but I want the focus also to be transferred to that tab – Mandeep Jain Jan 30 '14 at 13:48
  • I thought `window.open()` opens up a popup. – Peter Chaula Nov 28 '17 at 05:37
1

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

tzerb
  • 1,433
  • 1
  • 16
  • 35
0

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

srsajid
  • 1,717
  • 15
  • 12