Skip to content

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 websites 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 a simple HTML anchor tag and onclick attribute to open 2 URLs on a 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 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

1 thought on “Open Multiple URLs with one click JavaScript | Example code”

Leave a Reply

Discover more from Tutorial

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

Continue reading