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 window.open() the method as the best option in javascript.

window.open() method take two parameters,

  1. URL
  2. _blank value

To know more about window.open() method check here: https://developer.mozilla.org/en-US/docs/Web/API/Window/open

Syntax:

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 #window.open() #JavaScriptwindow.openNewTtab

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 155

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
mariobet - supertotobet - escort -

takip7.com