I'm using the code below with window.open to open a new link (same origin) in a new tab. If a tab with the new link is already open, the open tab should be focused instead.
This is all working fine, the focused tab is however always refreshed when it gains focus by this. How can I stop the focused tab from refreshing?
window.open(`./${_id}`, `module_${_id}`);
Check if the window is closed orelse use focus(), this should not refresh the page.
var windowObject = null; // global variable
function openURL(url) {
if(windowObject == null || windowObject.closed) {
windowObject= window.open(url);
} else {
windowObject.focus();
}
}
<button value="Check" onClick="openURL('https://www.google.com')"></button>