How to redirect after click on button?

Member

by adan , in category: Third Party Scripts , 6 months ago

How to redirect after click on button?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by addison , 6 months ago

@adan 

You can redirect the user to another page after they click on a button by using JavaScript. Here is an example code for redirecting the user to a different URL after clicking on a button:


HTML:

1
<button id="redirectButton">Click me to redirect</button>


JavaScript:

1
2
3
document.getElementById("redirectButton").addEventListener("click", function() {
  window.location.href = "https://www.example.com";
});


In this code, we use the addEventListener method to listen for a click event on the button with the id "redirectButton". When the button is clicked, we use window.location.href to redirect the user to the specified URL (in this example, "https://www.example.com"). You can replace this URL with the desired destination for the redirection.

Related Threads:

How to redirect on button click in react.js?
How to click button from ember.js controller?
How to update graphql query on button click?
How to display input with the click of a button in vue.js?
How to make <iframes> load only on a button click?
How to remove tooltips on line when click button in d3.js?