最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - how can you open a new page using javascript - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

4 Answers 4

Reset to default 8

Yes

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:

  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)

  1. 暂无评论