window.location.href not working

Vineet Basantani

This is my script:

<script type="text/javascript">
    $(document).ready(function(){
        $("#login").click(function(){
            var user = $('#userID').val(); 
            var pass = $('#password').val();
            if (user === '' || pass === ''){
                alert("Please Fill Required Fields");
            } 
            else {
                alert (user+" " +pass);
                var x="<?php confirm();?>";
                alert (x);
                window.location.href = 'http://localhost/Annapoorna/Welcome_Page.php';
            }
        });
    });
</script>

And my HTML

<form class="login-form"> 
    <input type="text" placeholder="username" name="userID" id="userID"/>
    <input type="password" placeholder="password" id="password"/>
    <button id="login" name="login" value="login">Login</button>
</form>

The alerts are coming right but window.location.href is not redirecting to the specified page. Why?

Randy

Why it doesn't work

Display the href (URL) of the current page:

document.getElementById("demo").innerHTML =
"Page location is " + window.location.href;

Result is:

Page location is http://www.yoururl.com/yourlocation


To make it work

To redirect to another page, you can use:

window.location="http://www.yoursite.com";

expand for working example

function Redirect() {
  window.location="http://www.yoursite.com";
}
    <html>
       <head>
                    
       </head>
       
       <body>
          <p>Click the following button, you will be redirected to home page.</p>
          
          <form>
             <input type="button" value="Redirect Me" onclick="Redirect();" />
          </form>
          
       </body>
    </html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript window.location.href onClick not working

From Dev

window.location.href not working in IE 11

From Dev

$window.location.href NOT WORKING in AngularJS

From Dev

JavaScript window.location.href not working in localhost

From Dev

window.location.href not working on IE

From Dev

window.location.href and hash are not working on chrome

From Dev

Javascript window.location.href onClick not working

From Dev

window.location.href not working as expected

From Dev

`window.location.href` not working as intended

From Dev

window.location.href isn't working

From Dev

*ngIf window.location.href.indexOf is not working

From Dev

Redirect a Website to a local folder Using window.location.href() not working

From Dev

window.location.href not working, mod rewrite or jquery?

From Dev

preventDefault stops window.location.href from working

From Dev

window.location.href not working after Response.End()

From Dev

location.href not working

From Dev

String is not a function on window location href

From Dev

window.location = '' is not working ;

From Dev

window location not working javascript

From Dev

angular4 unit test for window.location.href redirect to external link not working

From Dev

Enable and disable window.location.href

From Dev

onclick window.location.href with input value

From Dev

Passing parameter through "window.location.href"

From Dev

onchange event on window.location.href

From Dev

Window.location.href infinite loop

From Dev

Stubbing window.location.href with Sinon

From Dev

Using a variable for if window.location.href.indexOf()

From Dev

window.location.href appending instead of replacing

From Dev

window.location.href is not redirecting html page

Related Related

HotTag

Archive