Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What's the best way to open new browser window using JavaScript?
The open() method of window object is the best way to open new browser window using JavaScript
Following is the code for opening new browser window using JavaScript −
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>Open new browser window using JavaScript</h1>
<br />
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button open a new browser window</h3>
<script>
let BtnEle = document.querySelector(".Btn");
BtnEle.addEventListener("click", (event) => {
window.open("https://www.google.com");
});
</script>
</body>
</html>
Output

On clicking the ‘CLICK HERE’ button, it will redirect to the specified website −

Advertisements
