How To

How to Open a New Web Page On Button Click Using JavaScript

Opening a link or redirecting a user to a new page on our website using a button on click event is possible with JavaScript.

Often we use <a> tag to redirect users on a new page or to open a new link. However, on some special occasions, we have to redirect the user on the button click event using JavaScript.

How to Open a New HTML Page On Button Click in JavaScript

There are few methods to redirect or to open a new HTML page or link on button click event using JavaScript.

Method 1: Using Window.open()

This method is a straightforward approach to redirect the user to a new page.

<html>
 <head>
  <title>Open new HTML page or Redirect page using window.open()</title>
 </head>
 <body>
  <p>Redirect in same page</p>
  <button >

Method 2: Using JavaScript

This method is quite a unique way to redirect users. This method redirects users and leaves the same expression as the user opens a link via <a> tag on the web-page.

<html>
 <head>
  <title>Redirect or Open new Web page using JavaScript</title>
 </head>
 <body>
  <button >

Read Also: How to Disable TextBox/Input Field Onclick Using JavaScript

Conclusion

Here, we learnt how to open a new HTML web page on button click using JavaScript. However, we can use the same code to redirect the user from one page to another. In addition, Redirecting users is an essential factor in maintaining the bounce rate and SEO. I hope you understand the complete methodology of redirection users on button click using JavaScript.

Happy Scripting 🙂

Nachiket Panchal

Founder & Administrator of `errorsea` Having interest in Programming & Technology.

Recent Posts

5 Important Things To Know About WordPress Before You Use It

There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…

3 years ago

How to Install MySQL on Your PC in 3 Easy Steps

In this tutorial, I'm going to show you how to install MySQL on your computer.…

5 years ago

Download and Install Turbo C++ for Windows 10 (Full Installation Guide)

Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…

5 years ago

PHP .HTACCESS Redirects

We can redirect any webpage to any other or redirect the whole domain or website…

5 years ago

PHP Redirect Pages

There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…

5 years ago

PHP Include & Required

Include files in PHP are used in appending various global or config files. We can…

5 years ago