Home » Open URL in New Tab Using JavaScript

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 <a> 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,

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 of Open URL in New Tab using JavaScript

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

Also Check:

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

Happy Coding..!

Was this article helpful?


12 thoughts on “Open URL in New Tab Using JavaScript”

  1. Pingback: CSS Background Image Text Effect - PHPCODER.TECH

  2. Pingback: JavaScript Append HTML to Body - PHPCODER.TECH

  3. Pingback: Detect URL Change in JavaScript Without Refresh - PHPCODER.TECH

  4. Pingback: Check If Folder Or File Exists Using JavaScript - PHPCODER.TECH

  5. Pingback: Check If String Contains Exact Match in JavaScript - PHPCODER.TECH

  6. Pingback: How to Create Pagination in PHP with Ajax - PHPCODER.TECH

  7. Pingback: User Login Form Validation using Ajax in PHP - PHPCODER.TECH

  8. Pingback: Get Selected Date From Calendar in PHP using Ajax - PHPCODER.TECH

  9. Pingback: Migrate WordPress Site To New Host Manually - PHPCODER.TECH

  10. Pingback: Create Repository & Push Code To GitHub First Time - PHPCODER.TECH

  11. Pingback: 2 Ways To Check if Email already exists Using PHP - PHPCODER.TECH

  12. Pingback: JavaScript For Loop Complete Guide With Example - PHPCODER.TECH

Leave a Reply

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