3

This is my HTML so far

<button type="button" formaction="contact.html">Get In Touch!</button>

For some reason when I click on the button in a browser it doesn't take me to the contact.html page. All the pages that came up in google helped me learn new button attributes, but I couldn't figure out how to make the page redirect on click.

bfunphoto
  • 105
  • 1
  • 3
  • 9
  • 1
    This has been answered here: [http://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link](http://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link) – plhyhc Jan 15 '16 at 23:43
  • 1
    Why not use a normal link instead? Format it via CSS to look as “button-y” as you want. – CBroe Jan 15 '16 at 23:43
  • @CBroe DOH! Don't know why I didn't just think of that haha. Thanks for the help! – bfunphoto Jan 15 '16 at 23:47
  • 1
    `formaction` is only supported for `type="submit"` (See: [HTML button tag](http://www.w3schools.com/tags/tag_button.asp)) – Daniel Schneiter Jan 15 '16 at 23:49

4 Answers4

4

If you are using bootstrap, you can use this to do it for you:

<a href="#" class="btn btn-info" role="button">Link Button</a>

See http://www.w3schools.com/bootstrap/bootstrap_buttons.asp

Daniel
  • 301
  • 4
  • 13
  • I just want to add that if you are using Google Analytics to monitor your site, a normal hyperlink with would be an easier solution to track clicks. – Orden Jan 16 '16 at 00:01
1

Try the following:

<input type="button" onclick="location.href='contact.htm';" value="Contact" />

The better way is that you surround the above code with <form></form>.

Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110
1

Try these methods:

<!-- Using window.location.href = 'URL' -->
<button onclick='window.location.href = "https://stackoverflow.com"'>
  Click Me
</button>

<!-- Using window.location.replace('URL') -->
<button onclick='window.location.replace("https://stackoverflow.com")'>
  Click Me
</button>

<!-- Using window.location = 'URL' -->
<button onclick='window.location = "https://stackoverflow.com"'>
  Click Me
</button>

<!-- Using window.open('URL') -->
<button onclick='window.open("https://stackoverflow.com","_self","","")'>
  Click Me
</button>

<!-- Using window.location.assign('URL') -->
<button onclick='window.location.assign("http://www.stackoverflow.com")'>
  Click Me
</button>

<!-- Using HTML form -->
<form action='https://stackoverflow.com' method='get'>
  <input type='submit' value='Click Me'/>
</form>

<!-- Using html anchor tag -->
<a href='https://stackoverflow.com'>
  <button>Click Me</button>
</a>
Adnan Toky
  • 1,756
  • 2
  • 11
  • 19
0

How about this?

<a href="contact.html"><button type="button">Get In Touch!</button></a>
Falling10fruit
  • 197
  • 1
  • 12