How to Redirect a Webpage using jQuery?

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.

spot_img

Subscribe

Related articles

How to get million views on youtube?

To get a million views on YouTube, you will...

Can I create a custom dashboard in react?

Yes, you can create a custom dashboard in React....

All You Need to Know About Xbox 360 Backward Compatibility

The Xbox 360 works well with some games that...

How to Check if an Array has More than One Element in PHP?

An array is a group of data structures. In...

Learn How to Select All in VIM?

Now is the time to improve your VIM skills...
spot_img
Peter Graham
Peter Grahamhttps://fix-iphones.com
Hi there! I'm Peter, a software engineer and tech enthusiast with over 10 years of experience in the field. I have a passion for sharing my knowledge and helping others understand the latest developments in the tech world. When I'm not coding, you can find me hiking or trying out the latest gadgets.

LEAVE A REPLY

Please enter your comment!
Please enter your name here