Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: location.href to open in new window/tab?

I have a JavaScript file from a third party developer. It has a has link which replaces the current page with the target. I want to have this page opened in a new tab.

This is what I have so far:

if (command == 'lightbox') {  location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual"; } 

Can anyone help me out?

like image 931
iamjonesy Avatar asked Feb 28 '11 12:02

iamjonesy


People also ask

Can you make the link open in a new tab JavaScript?

You need to use the _blank value in the target attribute to open the linked URL in a new tab or window. If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window. open() method opens a new browser window.

How do I make a link open in a new tab in HTML?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.

How do I make a link open in a new tab instead of a new window?

The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.

How do you open a new window with JavaScript?

You can use JavaScript to launch a new window. The window. open() method, which allows you to open up new browser window without navigating away from the current page. It is useful when you need to display some popup advertisement or the instructions without navigating away from the current window.


1 Answers

window.open(   'https://support.wwf.org.uk/earth_hour/index.php?type=individual',   '_blank' // <- This is what makes it open in a new window. ); 
like image 108
alex Avatar answered Sep 22 '22 08:09

alex