How to Open URL in New Tab using JavaScript

HTML <a> target attribute provides an easy and simple way to open the linked URL in the new browser window or tab. You need to use the _blank value in the target attribute in the anchor tag to open the linked URL in a new tab or window.

<a href="https://www.codexworld.com" target="_blank">Visit CodexWorld</a>

If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window.open() method opens a new browser window. Use _blank in the second parameter of window.open() method to open a URL in a new tab using JavaScript.

The following JavaScript code will open https://www.codexworld.com URL in a new browser tab or window.

window.open('https://www.codexworld.com', '_blank');

9 Comments

  1. Jasdeep Singh Said...
  2. !!Raptor Said...
  3. M Kashi Said...
  4. Andrew J Barone Said...
  5. CORRIT Said...
  6. Vacana Studio Said...
  7. Gopi Said...
  8. Dipen Said...
  9. Mario Molinito Said...

Leave a reply

keyboard_double_arrow_up