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. But sometimes it requires opening a URL with JavaScript. 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 in a new browser tab or window.

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

Leave a reply