JavaScript: location.href to open in new window/tab?
I have a JavaScript file from a third party developer. It has a has link which replaces the current page with the target. I want to have this page opened in a new tab.
This is what I have so far:
if (command == 'lightbox') {
location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual";
}
Can anyone help me out?
window.open(
'https://support.wwf.org.uk/earth_hour/index.php?type=individual',
'_blank' // <- This is what makes it open in a new window.
);
If you want to use location.href
to avoid popup problems, you can use an empty <a>
ref and then use javascript to click it.
something like in HTML
<a id="anchorID" href="mynewurl" target="_blank"></a>
Then javascript click it as follows
document.getElementById("anchorID").click();