JavaScript open URL in new tab | Example code

Use window.open() method to pen URL in new tab, but it could be open in 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 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 this 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.