i have code that sets
window.location.href = [someurl]
but i want to have it open up in a new tab. Is there anyway to have the above code include
target="_blank"
from javascript?
i have code that sets
window.location.href = [someurl]
but i want to have it open up in a new tab. Is there anyway to have the above code include
target="_blank"
from javascript?
Share Improve this question asked Apr 25, 2011 at 12:22 leoraleora 197k367 gold badges906 silver badges1.4k bronze badges4 Answers
Reset to default 8Yes
window.open([someurl], "_blank");
or since _blank is the default
window.open([someurl]);
Use window.open()
https://developer.mozilla/en/DOM/window.open
window.location.href
just changes the location of the current window.
To open a new window, you will need to use yet another ready-made JavaScript function. Here is what it looks like:
window.open('url to open','window name','attribute1,attribute2')
This is the function that allows you to open a new browser window for the viewer to use. Note that all the names and attributes are separated with a ma rather than spaces. Here is what all the stuff inside is:
'url to open'
This is the web address of the page you wish to appear in the new window.'window name'
You can name your window whatever you like, in case you need to make a reference to the window later.'attribute1,attribute2'
As with alot of other things, you have a choice of attributes you can adjust.
window.location.open([someurl], [target="_blank"]);
sould be work.