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 use JavaScript.

But in both cased 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 and suggestion 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


Leave a Reply

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