0

Lets say you have code like this.

function openNewTab(url) {
      const newTab = window.open(url, 'windowNameHehe');
};

Now every time you call this function it will open a new tab. However, if the window is already opened it will go to it and refresh/reload it. How do I stop it from reloading/refreshing and just bringing it to view? Doing something like newTab.focus() or adding the boolean (true/false) in the 4th parameter of window.open isn't working for me either. Any help?

christiancn7
  • 175
  • 2
  • 3
  • 10

2 Answers2

0
function openNewTab(url) {
  var newTab = window.open(url, 'windowNameHehe', , false);
  newTab.focus();
}

https://www.w3schools.com/jsref/met_win_open.asp

Open a URL in a new tab (and not a new window) using JavaScript

Chris Chen
  • 1,228
  • 9
  • 14
0
function openNewTab(url) {
  const newTab = window.open('', 'windowNameHehe');
  newTab.focus();
  if (!newTab.location.hostname) {
    newTab.location.href = url;
  }
};
Dionis Oros
  • 664
  • 8
  • 12