jqueryHow can I use jQuery to redirect a user to a different page?
To use jQuery to redirect a user to a different page, you can use the window.location object. This object provides properties and methods for accessing and manipulating the current URL.
Example code
$(document).ready(function(){
window.location.href = "http://www.example.com";
});
The code above will redirect the user to the URL http://www.example.com when the document is ready.
The code consists of the following parts:
$(document).ready(function(){- This is a jQuery function that runs the code inside the brackets when the document is ready.window.location.href = "http://www.example.com";- This sets thehrefproperty of thewindow.locationobject to the URLhttp://www.example.com.});- This closes the$(document).ready(function(){function.
Helpful links
More of Jquery
- How do I add a zoom feature to my website using jQuery?
- How can I use jQuery to zoom an image when the user hovers over it?
- How do I use jQuery to detect window resize events?
- How do I use jQuery to execute code when the window has finished loading?
- How do I decide which one to use when comparing jQuery and React for software development?
- How do I use a jQuery x-csrf-token?
- How do I update to the latest version of jQuery?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zip files?
- How do I use jQuery to change the z-index of an element?
See more codes...