Skip to content

JavaScript open URL | Examples code

  • by

To open URL in the browser window, or a new tab use Window open() Method in JavaScript Or inside HTML tag. It will depend on your browser setting or parameters passed in the window.open() method that either a new window or tab will open. It is a pre-defined window method of JavaScript.

Syntax

window.open(URL, name, specs, replace); 

This function can use without the window keyword.

JavaScript open URL Examples

HTML examples code:

Open URL

It will open in tab. ( check browser setting popup block)

<html>  
<body>  

	<script>
		window.open('https://www.eyehunts.com')
	</script>

</body>  
</html>  

Open URL with button

In this example using HTML tag and onclick attribute without JavaScript opening URL

<html>  
<body>  

	<button onclick="window.open('https://www.eyehunts.com')"> Open Window </button>  
</body>  
</html>  

Open blank Tab with height and width

<html>  
<body>  

	<script>
		window.open("", "", "width=200,height=100");
	</script>

</body>  
</html>  

Output:

JavaScript open URL

Must Read: Open multiple tabs

Do comment if you have any suggestions and doubts on this topic.

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

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