Open Multiple URLs with one click JavaScript | Example code

The open() method to opens a new browser window, or multiple new tab in JavaScript.

Example Open Multiple URLs with one click JavaScript

HTML example Code: open multiple windows on single click.

Use onclick method to call window.open(‘url’). We created a function for it. Using a for loop for multiple website open.

<!DOCTYPE HTML>
<html>

<body>
	<a href="#" onclick="yourlink()">Click Here</a>

	<script>

		function yourlink() {

			var locs = ['site.com','site2.com','site3.com'] 

			for (let i = 0; i < locs.length; i++) {
				window.open(locs[i])}
			};

		</script>
</body>
</html>					

Output: window.open is sometimes blocked by popup blockers and/or ad-filters.

Open Multiple URLs with one click JavaScript

Open 2 Multiple URLs on one click button JavaScript Output

Open 2 Multiple URLs on one click button JavaScript

Another way without using JavaScript

You can just use simple HTML anchor tag and onclick attribute to open 2 URL on single click.

<!DOCTYPE HTML>
<html>

<body>
	<a href="#" onclick="window.open('http://google.com');
    window.open('http://yahoo.com');">Click to open Google and Yahoo</a>
</body>
</html>					

Do comment if you have any doubts and suggestion 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.