how can you open a new page using javascript
i have code that sets
window.location.href = [someurl]
but i want t开发者_C百科o have it open up in a new tab. Is there anyway to have the above code include
target="_blank"
from javascript?
Yes
window.open([someurl], "_blank");
or since _blank is the default
window.open([someurl]);
Use window.open()
https://developer.mozilla.org/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 comma 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.
精彩评论