HTML
How do I create an HTML button that acts like a link? So that clicking the button redirects the user to a page.
The plain HTML way is to put it in a <form> to specify the desired target URL in the action attribute.
Code:<form action="https://google.com"><a href="https://google.com" class="button">Go to Google</a>
<input type="submit" value="Go to Google" />
</form>
|
CSS
If CSS is allowed, simply use an <a>
Code:<a href="https://google.com" class="button">Go to Google</a>
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: initial;
}
|
Or pick one of those many CSS libraries like Bootstrap.
Code:<a href="https://google.com" class="btn btn-primary">Go to Google</a>
|
JavaScript
If JavaScript is allowed, set the window.location.href.
Code:<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />
|