Skip to main content

JavaScript - Open multiple Tabs

script.js

const google = "https://www.google.com/";
const yahoo = "https://www.yahoo.com/";
const microsoft = "https://www.microsoft.com/";

// function to open multiple tabs at once
function openTabs() {
  window.open(google);
  window.open(yahoo);
  window.open(microsoft);
}
index.html

<html>
  <head>
    <meta charset="UTF-8" />
    <script src="script.js"></script>
    <link rel="stylesheet" type="text/css" href="styles.css" />
  </head>

  <body>
    <div id="divContent">
      <h1>JavaScript : Open Multiple Tabs</h1>
      <button onclick="openTabs()">Open Tabs</button>
    </div>
  </body>
</html>
styles.css

@import url("https://fonts.googleapis.com/css2?family=Raleway&display=swap");

body {
  background: #edeae0;
  padding: 50px;
  font-family: "Raleway", sans-serif;
}

h1 {
  margin-bottom: 50px;
  background-color: #efdecd;
  padding: 25px;
}

button {
  background-color: #58111a;
  border: 2px solid #f7e7ce;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

#divContent {
  width: 700px;
  margin: auto;
  padding-bottom: 25px;
  background-color: #faebd7;
  text-align: center;
  display: block;
}
More JavaScript tutorials