Trying to open a new tab from an existing one and saving the link of the newly opened tab in local storage. Despite using the following JS code, the link is not being stored locally. The original plan was to execute a callback once the tab had finished loading.
function openAndSetUrl(tabName, callback) {
var newWindow = window.open("https://google.com", tabName);
if (newWindow) {
newWindow.onload = function() {
var url = newWindow.location.href;
localStorage.setItem(tabName, url);
if (typeof callback === 'function') {
callback(url);
}
}
}
}
function openInNewTab(tabName) {
openAndSetUrl(tabName, function(url) {
console.log("URL set to:", url);
});
}