Skip to content

Open multiple tabs with one link | JavaScript code

For example, we want to open 2 URLs (http://google.com and http://yahoo.com) in a different tab with one link click. You can do it in 2 ways defining in a tag or using JavaScript.

But in both cases, you have to use a window.open method.

Open multiple tabs with one link Examples

Here is a basic implementation in JavaScript-

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

</body>  
</html>  

Window open method in HTML tag

<!DOCTYPE HTML>
<html>

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

	<script>

		function yourlink() {

			var locs = ['http://google.com', 'http://yahoo.com'] 

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

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

Output:

Open multiple tabs with one link

Note: Unblock the pop-up windows for your browser and the code could work.

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

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

OS: Windows 10

Code: HTML 5 Version

1 thought on “Open multiple tabs with one link | JavaScript code”

Leave a Reply

Discover more from Tutorial

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

Continue reading