In HTML, the anchor tag is used to open URLs in a new tab in an elementary and straightforward manner. More about this tag can be learnt from this article. However, sometimes there’s a need to do the same using Javascript. In this case window.open() method proves to be helpful. The window.open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values.
Approach:
- To open a new tab, we have to use _blank in second parameter of window.open().
- The return value of window.open() is a reference to the newly created window or tab or null if it failed.
- Do not add a third parameter to it as it will result in the opening of a new window rather than a tab
Syntax:
window.open(URL, '_blank');
Example 1:
<html> <body> <p>Click the button to open a new tab </p> <button onclick="NewTab()"> Open Geeksforgeeks </button> <script> function NewTab() { window.open( } </script> </body> </html> |
Output:

Example 2:
<html> <body> <p>Click the button to open google.</p> <button onclick="Open()">Geeksforgeeks</button> <script> function Open() { } </script> </body> </html> |
Output :

Recommended Posts:
- How to open URL in a new window using JavaScript ?
- Open a link without clicking on it using JavaScript
- Open all persons solution links from submission page using JavaScript
- What does '<?=' short open tag mean in PHP ?
- What is OAuth (Open Authorization) ?
- How to open a PDF files in web browser using PHP?
- Node.js | fs.open() Method
- HTML | open Attribute
- HTML | DOM open() Method
- PHP | XMLReader open() Function
- AngularJS | ng-open Directive
- How to open a different modal that is inside of a list ?
- What is ODI(Open Data link Interface)?
- How to open popup using Angular and Bootstrap ?
- HTML | <details> open Attribute
- HTML DOM indexedDB open() Method
- HTML | dialog open Attribute
- HTML | DOM Details open Property
- Node.js | fsPromises.open() Method
- Open shortest path first (OSPF) - Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


