How to Redirect to Another Page in JavaScript on button click

Last Updated On Tuesday 24th May 2022

On Button Click ReDirect to Another Page

Sometimes You may want to use a button to link to another page or website.

Add an onclick event to the button.

	<button onclick="location.href = 'example.com';" id="myButton">
Button
</button>
	
	<button id="myButton">Home</button>
	
	document.getElementById("myButton").onclick = function () {
     location.href = "example.com";
};
	

Name A function to HTML Element

HTML Button onClick Redirect

	<button name="redirect" onClick="redirect()">
	
	function redirect() {
   let url = "http://example.com";
   window.location(url);
}
	

You could change the action attribute of the form on Click the button

	myFun(){
   $('form').attr('action','new path');
}
	

How to redirect to another page using JavaScript?

References

onclick redirect to another page
redirect on button click
button to redirect to another page html
button onclick to another page
how to redirect to another page in html
html button redirect to another page
javascript onclick redirect
javascript redirect to another page