开发者

how can you open a new page using javascript

开发者 https://www.devze.com 2023-02-28 18:50 出处:网络
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

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:

  1. 'url to open' This is the web address of the page you wish to appear in the new window.

  2. 'window name' You can name your window whatever you like, in case you need to make a reference to the window later.

  3. '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.

0

精彩评论

暂无评论...
验证码 换一张
取 消