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”

  1. Is there any way that the user does not need to do the unblock the popup windows for the browser and still multiple tabs could open?
    Thanks in advance.

Leave a Reply

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