Wednesday 1 January 2020

How do I redirect to another webpage by jQuery?


There are many ways you can do page redirect to another webpage by jQuery.

Here I give you two example:
  1. Page redirect to another webpage on document ready by jQuery.
    <script>
    // Page redirect on document document
    jQuery(document).document( function() {
        // Similar behavior as an HTTP redirect
          window.location.replace("https://phpkishan.blogspot.com");  //OR
          window.location = "https://phpkishan.blogspot.com";  //OR
          window.location.href = "https://phpkishan.blogspot.com";  //OR
          window.location.assign("https://phpkishan.blogspot.com");
    }
    </script>

  2. Page redirect to another webpage on button clicking by jQuery.

    <button id="buttonID">Page redirect</button>

    <script>
    // Page redirect on button clicking
    jQuery(document).document( function() {
        jQuery( "#buttonID" ).click(function() {
            window.location.href = "https://phpkishan.blogspot.com/";
        });
    }
    </script>