How can I make a button redirect my page to another page?
Just add an onclick
event to the button
:
<button onclick="location.href = 'www.yoursite.com';" id="myButton" class="float-left submit-button" >Home</button>
But you shouldn't really have it inline like that, instead, put it in a JS block and give the button
an ID:
<button id="myButton" class="float-left submit-button" >Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "www.yoursite.com";
};
</script>
Make an HTML button redirect me to another page
Try wrapping button in form tag like this:
<form action="index.html">
<button type="submit" onclick="register()">Create new account</button>
</form>
How to redirect from one page to another in HTML site using HTML button
<input type="button" onclick="document.location.href = 'http://google.com'" />
or without JS
<form action="/contact.html">
<input type="submit">
</form>
How to make a button redirect to another page using jQuery or just Javascript
Without script:
<form action="where-you-want-to-go"><input type="submit"></form>
Better yet, since you are just going somewhere, present the user with the standard interface for "just going somewhere":
<a href="where-you-want-to-go">ta da</a>
Although, the context sounds like "Simulate a normal search where the user submits a form", in which case the first option is the way to go.
How do I create an HTML button that acts like a link?
HTML
The plain HTML way is to put it in a <form>
wherein you specify the desired target URL in the action
attribute.
<form action="https://google.com">
<input type="submit" value="Go to Google" />
</form>
If necessary, set CSS display: inline;
on the form to keep it in the flow with the surrounding text. Instead of <input type="submit">
in above example, you can also use <button type="submit">
. The only difference is that the <button>
element allows children.
You'd intuitively expect to be able to use <button href="https://google.com">
analogous with the <a>
element, but unfortunately no, this attribute does not exist according to HTML specification.
CSS
If CSS is allowed, simply use an <a>
which you style to look like a button using among others the appearance
property (it's only not supported in Internet Explorer).
<a href="https://google.com" class="button">Go to Google</a>
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: initial;
}
Or pick one of those many CSS libraries like Bootstrap.
<a href="https://google.com" class="btn btn-primary">Go to Google</a>
JavaScript
If JavaScript is allowed, set the window.location.href
.
<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />
Instead of <input type="button">
in above example, you can also use <button>
. The only difference is that the <button>
element allows children.
Is there a way to make a button redirect to the page of the current link, but in another language
Just replace double quotes with single quotes in .replace("en", "el")
So:
<input type="button" onclick="location.href=window.location.href.replace('en', 'el');" value="Greek" />
However, it's better to do like this:
<input type="button" id="change-lang" value="Greek" />
<script>
document.getElementById("change-lang").addEventListener("click", function(){
location.href=window.location.href.replace('en', 'el');
});
</script>
On a button click, redirect to a new page using href and also invoke a javascript function using onclick at the same time
Add this at the end of your "onclick" function:
window.location.href = "https://url.com";
Related Topics
"Pointer-Events: None" Does Not Work in IE9 and Ie10
How to Change HTML Object Element Data Attribute Value in JavaScript
CSS Height 100% Percent Not Working
How to Play HTML5 Video in Reverse
How to Detect Supported Video Formats for the HTML5 Video Tag
How to Rotate a Single Object on an HTML 5 Canvas
JavaScript on the Bottom of the Page
Increment a Number in a String in with Regex
Counting and Limiting Words in a Textarea
Html5 Display Audio Currenttime
How to Tell If a Browser Supports <Input Type='Date'>
Changing the Order of Elements
JavaScript Code Not Work in Head Tag
How to Detect Escape Key Press with Pure Js or Jquery
Js - Window.History - Delete a State