How to Redirect to Another Web Page Using jQuery

This quick post shows how to redirect to another web page using jQuery.
Let's first see how to use vanilla javascript to redirect to another web page.
There are a couple of ways to redirect to another webpage with JavaScript. The most popular ones are location.href and location.replace:
Example:
// Simulate a mouse click:
window.location.href = "https://www.javaguides.net/";

// Simulate an HTTP redirect:
window.location.replace("https://www.javaguides.net/");

How to Redirect to Another Web Page Using jQuery

Refer below the single line of code to redirect from one page another page using JQuery:
$(location).attr('href','https://www.javaguides.net');
Here is a complete web page which redirects to another URL using jQuery:
<html>
   <head>
      <title>how to redirect to another web page using jQuery</title>
   </head>
   <body>
      <h2>how to redirect to another web page using jQuery</h2>

      <script
   src="https://code.jquery.com/jquery-3.4.1.min.js"
   integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
   crossorigin="anonymous"></script>
      <script>
         $(document).ready(function() {
            $(location).attr('href','https://www.javaguides.net');
         });
      </script>
   </body>
</html>
Open above web page in the browser will navigate to 'https://www.javaguides.net' web page using jQuery.

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments

  1. Although the number of symbols finally increased to about 22, permitting 10,648 combos, this still restricted jackpot sizes 메리트카지노 as well as|in addition to} the number of possible outcomes. And Musicbed desires to positive you|ensure you|be certain to} find the proper music for your project. Not solely do they have unbelievable browse and search instruments, but they also have individuals on staff who are devoted to helping you discover the proper music. At no extra charge they’ll ship you ideas primarily based on what you’re on the lookout for. So, that is why you need to guess once more, you need to put some more money in, after which when you do win, you may have that decision and it's the sense of relief that comes together with it.

    ReplyDelete

Post a Comment