How to Open Another HTML Page in JavaScript?

Estimated read time 1 min read

You can open another HTML page in JavaScript using the window.open() method.

Here’s an example:

function openPage() {
  window.open("https://www.example.com/page2.html", "_blank");
}

In this example, calling the openPage function will open the URL “https://www.example.com/page2.html” in a new browser window or tab (depending on the browser’s settings). The second argument, "_blank", specifies that the page should be opened in a new window. If you change it to "_self", the page will be opened in the same window.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply