How to Redirect a Webpage using jQuery?

spot_img

Share This Post

Redirecting a user from one page to another, or even from your website to another, maybe accomplished in a variety of ways.

We’ll go through how to achieve this operation utilizing the jQuery library as well as pure JavaScript in this tutorial.

How to redirect to another page using jQuery?

Using jQuery to redirect a visitor to a different website is a simple one-liner.

Remember that this solution relies on the jQuery library, so make sure it’s installed before running the code. For this reason, the second solution is given above, which uses pure JavaScript, is preferable.

jQuery Solution

$(location).attr('href','http://google.com');

Let’s take a look at the vanilla JavaScript version, which is slightly different but preferable.

How to Redirect a Webpage using Pure Javascript?

The vanilla JavaScript version of this code is also a simple one-liner.

window.location.href = "http://google.com";

It’s as simple as that. You now know how to use jQuery to redirect a webpage. Unless you’re dead set on using jQuery, opt for the second pure JavaScript solution.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Posts

How to Choose Best Lift Chair?

For people with physical disabilities and the elderly, getting...

NuWave Brio Air Fryer Review

Craving for some fried goods but scared of the...

Commercial Toaster: Top Picks with Buying Guide and FAQs

Commercial Toaster: Top Picks with Buying Guide and FAQs...

Best High-Velocity Blower Fans

Does your room feel so warm during the summer?...

10 Best Xbox One Gaming Chair: Buying Guide And Reviews

For some people, console gaming should have the right...

Best Gaming Chairs Under 200$

Whether you game as a hobby or happen to...
spot_img
- Advertisement -spot_img