Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

popup - Redirect to a new tab within javascript file

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"?

question from:https://stackoverflow.com/questions/25331512/redirect-to-a-new-tab-within-javascript-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...