Reputation: 147
i want to redirect to home page using js function by its not redirecting to different page. getting error like this
file:///D:/dotnetapp/@Url.Content( net::ERR_FILE_NOT_FOUND
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit" onclick="login()">Sign in</button>
<script>
function login() {
var userid = document.getElementById("Username").value;
var password = document.getElementById("password").value;
if (userid == "administrator" & password =="password")
{
window.location = "home.html";
}
else
{
alert("username / password is incorrect");
}
}
</script>
Upvotes: 1
Views: 2175
Reputation: 42526
If it is on the same directory level/relative, you can use this instead.
window.location.href = '/home.html';
// or window.location.href = 'home.html';
Just some additional information for your reference,
window.location
is an object with various properties such as href
and hash
, whereas window.location.href
is a string itself. Either ways, setting both window.location
and window.location.href
to a string value should lead to a redirection to another page.
Upvotes: 2