Open URL in New Tab Using JavaScript

In HTML we use <a> tag for a hyperlink to another page. For Open URL in New Tab we use <a> tag target attribute.

In HTML <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,

<a href="http://www.phpcoder.tech" target="_blank">Visit PHPCODER.TECH</a>
Open URL in New Tab Using JavaScript

If you want to do the same thing or open in a new tab using JavaScript, then we can use the window.open() method as the best option in javascript.

window.open() method take two parameters,

  1. URL
  2. _blank value

Syntax of Open in New Tab JavaScript

window.open("URL", "_blank");

Below example is open http://www.phpcoder.tech URL in a new tab of the browser,

<html> 
  
<body> 
  
    <p>Click the button to open a new tab </p> 
  
    <button onclick="NewTabJS()"> 
      Open PHPCODER.TECH
  </button> 
  
    <script> 
        function NewTabJS() { 
            window.open("http://www.phpcoder.tech", "_blank"); 
        } 
    </script> 
  
</body> 
  
</html> 

Answers of:

  • how to open in new tab javascript?
  • how to open link in new tab javascript?
  • how to open URL in new tab javascript?
  • how to open page in new tab javascript?
  • how to make the link open in new tab javascript?
  • how to open in a new tab using javascript?
  • open in new tab javascript onclick

Also Check:

Tags: #javascript #window.open() #JavaScriptwindow.openNewTtab

Happy Coding..!

Add a Comment

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