I want to create an HTML button that will act as a hyperlink: when you click on the button, it should redirect the user to a specific page. I want the button to be as convenient as possible. I would also like the URL to have no additional characters or parameters.

How can I achieve this?

Now I do this:

<form method="get" action="/page2"> <button type="submit">Continue</button> </form> 

The problem is that a question mark is added to Safari and Internet Explorer at the end of the URL. I need to make sure that there are no additional characters at the end of the URL.

There are two possible solutions to this problem: the use of JavaScript and the design of a hyperlink in the form of a button.

Using JavaScript:

 <button onclick="window.location.href='/page2'">Continue</button> 

But this, of course, requires javascript, and for this reason will not work for screen readers.

The purpose of the hyperlink is to move to another page. Therefore, an attempt to make a button act as a link is an incorrect decision, that is, using a hyperlink and using styles to make it look like a button is not true.

 <a href="/page2>Continue</a> 

Translation of the question “ How to create an HTML button? » @Andrew .

1 answer 1

HTML

A simple way to do it with HTML is to format everything as a <form> , where you specify the target URL as the action attribute.

 <form action="http://google.com"> <input type="submit" value="Go to Google"> </form> 

If necessary, set the CSS property display: inline; on the form so that it moves along with the surrounding text.

CSS

If CSS is enabled, just use <a> , hyperlinking like a button using the appearance property and others ( only support for Internet Explorer at the moment (July 2015) is still very weak ).

 <a href="http://google.com" class="button">Go to Google</a> a.button { -webkit-appearance: button; -moz-appearance: button; appearance: button; text-decoration: none; color: initial; } 

Or choose one of the many CSS libraries like Bootstrap .

 <a href="http://google.com" class="btn btn-default">Go to Google</a> 

Javascript

If javascript is supported, install window.location.href .

 <input type="button" onclick="location.href='http://google.com';" value="Go to Google" /> 

Translation of the answer “ How to create an HTML button? » @Balusc .