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 thehref
property of thewindow.location
object to the URLhttp://www.example.com
.});
- This closes the$(document).ready(function(){
function.
Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How can I use JQuery with Yii2?
- How do I use jQuery to change the z-index of an element?
- How do I use jQuery to zip files?
- 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 zoom in or out on an element?
- How can I get the y position of an element using jQuery?
- How do I use a CDN to validate jQuery?
- How do I use the jQuery masked input plugin?
See more codes...