tags:

views:

52

answers:

3

is it possible to use a button as an hyperlink in html. and it should be working for all the browsers?

+2  A: 

Not really a hyperlink per se but you can take the user elsewhere with a button.

<input type="button" value="Go To Google" onclick="window.location='http://google.com'" />
Darrell Brogdon
+6  A: 

If you want to separate content (html) from behaviour (JavaScript), as oppose to what Darrel suggested I would use:

<form action="http://www.google.com"&gt;
<input type="button" value="go to goole" />
</form>

Even thought this is not a form proper, it will work fine, and degrade gracefully when JS is disabled.

sombe
Agreed. Though personally I think the ones who disable JavaScript are the same people who insist on investing in the buggy-whip industry. :)
Darrell Brogdon
Often this is not up to the user. Think about visually impaired people using reading systems, robots that don't interpret JS well, PDA's or any kind of not fully supporting apparatus. Being a developer, you have to separate your content from presentation, it's much more professional, i believe.
sombe
I would ask why the method here is "post". This form doesn't submit any data or anything, and making its method a post will cause warnings when using the back button or refresh button in many browsers.
Clueless
@Clueless, correct, edited.
sombe
+1  A: 

As a third alternative to the ones suggested here, you could use CSS to style a hyperlink to look like a button. If it works more like a link (goes somewhere, not performs an action), it may be better this way - for example, as far as I know, search engines may not always submit forms, but they would follow a link.

Jani Hartikainen