bfunphoto
bfunphoto

Reputation: 105

How can I make a button link to another page?

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.

Upvotes: 3

Views: 79492

Answers (4)

Falling10fruit
Falling10fruit

Reputation: 319

How about this?

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

Upvotes: 0

Adnan Toky
Adnan Toky

Reputation: 1943

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>

Upvotes: 1

Maihan Nijat
Maihan Nijat

Reputation: 9355

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>.

Upvotes: 1

Daniel
Daniel

Reputation: 311

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

Upvotes: 4

Related Questions