As of HTML5, buttons support the formaction attribute. Best of all, no JavascriptJavaScript or trickery is needed.
<form> <button formaction="http://stackoverflow.com">Go to Stack Overflow!</button> </form> Caveats
- Must be surrounded by
<form>tags. - The
<button>type must be "submit" (or unspecified), - I couldn't get it working with type "button." Which brings up the point below. - Overrides the default action in a form. In other words, if you do this inside another form it's going to cause a conflict.
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction Browserformaction
Browser Support: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Browser_compatibility<button>: The Button element