Skip to content
Advertisement

To open the already opened tab using window.open() function without reloading the already opened tab

I was writing OnClick javascript code to open the new web page.

Expectation: I want my to open the new page if that page is not already openend or open the already existing page without reload if that page is already opened.

My code: window.open(url,’dialers’).focus();

This code always reloads the child page if already opened. Please help to achieve my ask.

Advertisement

Answer

You can store the window object into a variable and call the focus() method multiple times like this:

let newWindow = window.open(url,'dialers')
newWindow.focus()
doThing()
newWindow.focus()
doAnotherThing()
newWindow.focus()
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement