Skip to content

JavaScript open URL in new tab | Example code

  • by

Use window.open() method to open URL in a new tab, but it could be open in the new browser window or a new tab depending on the browser setting and the parameter values.

window.open(URL, '_blank');

Example code open URL in a new tab in JavaScript

HTML example code:

Using _blank in the second parameter of window.open() to open a new tab in the example:-

<html>

<body>

	<script>
		function NewTab() {
			window.open("https://www.eyehunts.com", "_blank");
		}
		// calling function 
		NewTab();
	</script>

</body>

</html>

Output:

JavaScript open URL in new tab

Do comment if you have any doubts and suggestions on these JS URL examples.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading