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 2 Multiple URLs on one-click button JavaScript Output
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
Thanks for the examples. I was able to use it for popups.
Click to open Google and Yahoo
Click to open Google and bing