krishna mohan
krishna mohan

Reputation: 147

unable to redirect page using window.location in js

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

Answers (2)

wentjun
wentjun

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

axl-code
axl-code

Reputation: 2274

Try using

window.location.href = "home.html"

This link could be useful

Upvotes: 0

Related Questions