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 −