1

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>
krishna mohan
  • 135
  • 1
  • 15

2 Answers2

2

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.

wentjun
  • 40,384
  • 10
  • 95
  • 107
0

Try using

window.location.href = "home.html"

This link could be useful

axl-code
  • 2,192
  • 1
  • 14
  • 24