3

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?

4 Answers 4

8

Yes

window.open([someurl], "_blank");

or since _blank is the default

window.open([someurl]);
Sign up to request clarification or add additional context in comments.

Comments

3

Use window.open()

https://developer.mozilla.org/en/DOM/window.open

window.location.href just changes the location of the current window.

Comments

1

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.

Comments

0
window.location.open([someurl], [target="_blank"]);

sould be work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.