I have code that sets:
top.location.href = [someurl]
But I want it to open up in a new tab. Is there anyway to have the above code include: target="_blank"
?
Use the method window.open(url, target)
to open a new window (it depends on the browser or the user's settings whether the URL is opened in a new window or tab):
window.open('http://stackoverflow.com', '_blank');
For more information about window.open()
, read the documentation at w3schools.
Please note: Randomly opening a new window (or tab) isn't allowed in most browsers, because it is then treated as an "unwanted popup".