HTML: Use Button as Link
Question by Guest | Last update on 2021-07-06 | Created on 2014-09-18
I would like to use a button (<input type="button">) as a link (<a href=""></a>) on my website to call the page "download.php?id=1" with it.
Is it possible to repurpose a normal button in a way that it can be used and behaves like a usual hyperlink?
Related Topics
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
Mouseover buttons using CSS without reloading
Tutorial | 0 Comments
jQuery: Load and Replace DIV Content with clicking Links
Tutorial | 0 Comments
jQuery: Send HTML5 Canvas to Server via Ajax
Tutorial | 0 Comments
jQuery: Disable Submit Button if no Checkbox is selected
Tutorial | 7 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
Delphi/Lazarus: ShowModal Result
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can simply assign an OnClick-Event to your button to call the link with it.
For example in the following way:
If you are already using jQuery on your page, of course, it is more elegant to set an appropriate jQuery-event-listener.
However, both methods are only working, if JavaScript is activated.
Last update on 2021-07-06 | Created on 2014-09-18
Another possibility is to build an invisible form around the button.
As "action", you can just use your link, as "method" you can use "get" and the button type must be "submit".
With this way, it would also work if JavaScript is not activated.
Last update on 2021-07-06 | Created on 2014-09-18
In most browsers, it is also working by just enclosing the button with an a-tag to make it a "link".
However, this is not valid HTML.
Alternatively, you can build your own button using CSS:
.btlink { border: 1px solid #333; background-color: #EEE; padding: 4px 6px 4px 6px; display: block; text-decoration: none; }And here is how to apply it:
Of course, you can change this CSS to your own needs depending on you would like to style your button. For example like all of the other buttons on your website.
2014-09-18 at 23:46