Redirect from an HTML page
Try using:
<meta http-equiv="refresh" content="0; url=http://example.com/" />
Note: Place it in the <head>
section.
Additionally for older browsers if you add a quick link in case it doesn't refresh correctly:
<p><a href="http://example.com/">Redirect</a></p>
Will appear as
Redirect
This will still allow you to get to where you're going with an additional click.
redirect html page and open new tab with different URL
To solve it, you need to add setTimeout to function like this.
function changeLocation (){
setTimeout(function(){
window.location.replace("http://stackoverflow.com");
},200);
}
Redirect to another html page using only html and javascript
You have given the fields a
name
, not anid
so your code will throw an error before reaching the redirect.Is
admin.html
in the same scope/folder as this file? If not, you will need to specify the relative path toadmin.html
, eg:../otherFolder/admin.html
Have you tried using
window.location.replace(admin.html)
?
How do I redirect to another webpage?
One does not simply redirect using jQuery
jQuery is not necessary, and window.location.replace(...)
will best simulate an HTTP redirect.
window.location.replace(...)
is better than using window.location.href
, because replace()
does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco.
If you want to simulate someone clicking on a link, use
location.href
If you want to simulate an HTTP redirect, use location.replace
For example:
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
Redirect to another HTML page after successfull login attempt | with JS
A couple of things here. One you're doing a GET
with your form rather than doing a POST
. You should change that. Second, on your JavaScript call for auth
you should pass the event
parameter so that the default action of the form will be stopped. Third, you should be using a relative path for your URL
within your redirect. Last, You should do a window.redirect()
to simulate an HTTP redirect when the function executes.
Here is the code with the updates:
<form id="form" action="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email"
id="email"
class="form-control"
aria-describedby="emailHelp" >
<small id="emailHelp"
class="form-text text-muted">
We'll never share your email with anyone else.
</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" id="password" class="form-control" >
</div>
<button type="submit"
class="btn btn-outline-success btn-lg shadow"
onClick="auth(event)">Submit</button>
</form>
<script>
function auth(event) {
event.preventDefault();
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
if (email === "admin@gmail.com" && password === "user") {
window.location.replace("/upload.html");
} else {
alert("Invalid information");
return;
}
}
</script>
Redirect from an HTML page to another page to a title
you can use this
like
<script>
setTimeout(function(){location.replace("http://example.com/alternate_url.html");} , 0);
</script>
Related Topics
How to Disable Viewport Zooming on Mobile Safari
Html:How to Make a Curve Like This Using HTML & CSS Using Border or Box
Disable Blue Highlight When Touch/Press Object With Cursor:Pointer
Force HTML Content to Fit in Device Width With Wkwebview
Nested Ngfor Looping Over an Array of Objects
Angular, Image Not Found (Get 404)
Html/Css - Make Alert Disappear After a Few Seconds
How to Make My Website Fit Any Screen Size
How to Change the Time Format (12/24 Hours) of an <Input>
How to Make CSS Grid Items Take Up Remaining Space
How to Manually Trigger Click Event in Reactjs
How to Resize Image in Bootstrap Carousel
Html - How to Scroll Vertical in Select Box
How to Click a Button on a Website Using Puppeteer Without Any Class, Id ,... Assigned to It