Prevent window.open() from refreshing the window

Viewed 891

I hope you are great! May someone shed a light on this one

Use case

  1. Page A opens page B with window.open()

  2. Refresh page A and try to focus page B with window.open() again.

Code

if (!window.memwin || window.memwin.closed) {
    window.memwin = window.open(URL, "windowName", "",true)
}
window.memwin.focus();

Problem

The focus on page B happens but the page is reloaded. Is there any method to overcome this issue? I want the page B to be focused without been reloaded.

*(If page A is not reloaded then focus to page B with window.open() will not reload the page B)

1 Answers

It looks like there is a way to solve this.

  • In a cookie I save the state of the window(open/closed)

  • Use this to create the window

window.open(URL, "windowName", "",true)
  • Use this to focus back to the window
window.open('', "windowName", "",true)

By doing that user will be able to focus page B from everywhere. The only thing that we need to know is the windowName and if that is still opened or closed

Related