Redirect from an HTML Page

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

  1. You have given the fields a name, not an id so your code will throw an error before reaching the redirect.

  2. Is admin.html in the same scope/folder as this file? If not, you will need to specify the relative path to admin.html, eg: ../otherFolder/admin.html

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