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 download a zip file using jQuery?
- How do I add a zoom feature to my website using jQuery?
- How do I use jQuery to change the z-index of an element?
- How do I use jQuery to zoom in or out on an element?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I create a jQuery Yes/No dialog?
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How can I prevent jQuery XSS vulnerabilities?
- How can I convert XML data to JSON using jQuery?
See more codes...