I have the following code,
var newTab;
var url = uniqueUrlEveryTime;
if (!sessionStorage.getItem(url)) {
newTab = window.open(url, '_blank');
sessionStorage.setItem(url, newTab);
newTab.focus();
}
else {
sessionStorage.getItem(url).focus();
}
When the Url is present in the sessionStorage, I am trying to get the newTab object from sessionStorage and set its focus, but it is giving me an error. What am I doing wrong?
You set the session storage to be the url of the tab. Now you need to run through your tabs and check if the one of them has that url and then set .focus()
Some theoretical code below because I am not sure what your html for the tabs looks like
const tabUrl = sessionStorage.getItem(url)
if(tabUrl === newTab.url){newTab.focus() }