Open two tabs script

How to Create a Simple Script to Open Two Tabs: Step-by-Step Guide for Developers

How it Works:

  1. Replace https://example.com and https://anotherexample.com with the URLs you want to open.
  2. Clicking the “Open Tabs” button will trigger the openTwoTabs function.
  3. Each window.open() call opens a new tab with the specified URL.

Notes:

  • Browsers may block popups if they detect this as unsolicited behavior. Ensure this script is triggered by a user action (like a button click) to avoid being blocked.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Open Two Tabs</title>
    <script>
        function openTwoTabs() {
            const url1 = "https://example.com"; // Replace with your first URL
            const url2 = "https://anotherexample.com"; // Replace with your second URL

            // Open the two URLs in new tabs
            window.open(url1, "_blank");
            window.open(url2, "_blank");
        }
    </script>
</head>
<body>
    <h1>Open Two Tabs</h1>
    <button onclick="openTwoTabs()">Open Tabs</button>
</body>
</html>

Leave a Reply

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