简体   繁体   中英

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>

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.

Try using

window.location.href = "home.html"

This link could be useful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM