Open URL in New Tab Using JavaScript

In HTML we use an anchor tag <a> for a hyperlink to another page. For Open URL in New Tab Using JavaScript, we use the anchor tag target attribute to open in a new tab using JavaScript.

In HTML anchor <a> tag’s target attribute provides a simple way to open a new tab or new window of the browser. We use _blank as a value in the target attribute in the anchor tag. Check below,

Open URL in New Tab Using JavaScript

If you want to do the with javascript to open a link in a new tab, then we can use the the method as the best option in javascript. method take two parameters,

  1. URL
  2. _blank value

To know more about method check here:


Example of Open URL in New Tab By Using JavaScript

Below example shows provide URL open in new tab using JS.

Code Highlights:

  • In the above example, we create an HTML button where we call a JS function on onclick event to open in a new tab using JS code.
  • Now we create a JS script, where we use the window open method to open URL in a new tab by JavaScript.
  • Window open method takes two parameters,
    1. URL: which opens in new tab JS.
    2. To open in a new tab we mainly use _blank attribute as the second parameter.

Here is the complete source code and explanation of open URL in new tab using JS.

Also Check:

Tags: #javascript #JavaScriptwindow.openNewTtab

Happy Coding..!

Was this article helpful?
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
Posts created 189

13 thoughts on “Open URL in New Tab Using JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top