Sunday, 10 December 2017

How to create an HTML button that acts like a link?

itemprop="text">

I would like to create an HTML button
that acts like a link. So, when you click the button, it redirects to a page. I would
like it to be as accessible as possible.



I would
also like it so there aren't any extra characters, or parameters in the
URL.



How can I achieve
this?




/>

Based on the answers posted so far, I am currently
doing this:



action="/page2">
type="submit">Continue



but
the problem with this is that in href="http://en.wikipedia.org/wiki/Safari_%28web_browser%29"
rel="noreferrer">Safari and href="http://en.wikipedia.org/wiki/Internet_Explorer"
rel="noreferrer">Internet Explorer, it adds a question mark character to
the end of the URL. I need to find a solution that doesn't add any characters to the end
of the URL.




There are two other
solutions to do this: Using JavaScript or styling a link to look like a
button.



Using
JavaScript:



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


But
this obviously requires JavaScript, and for that reason it is less accessible to screen
readers. The point of a link is to go to another page. So trying to make a button act
like a link is the wrong solution. My suggestion is that you should use a link and href="https://stackoverflow.com/questions/710089/how-do-i-make-an-html-link-look-like-a-button">style
it to look like a
button.




            href="/link/to/page2">Continue


Answer




HTML



The
plain HTML way is to put it in a

wherein you
specify the desired target URL in the action
attribute.



            action="http://google.com">
/>




If
necessary, set CSS display: inline; on the form to keep it in
the flow with the surrounding text. Instead of type="submit"> in above example, you can also use type="submit">. The only difference is that the

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...