The jQuery API also allows you to redirect a web page to another URL in just one line of code. Though this is not the ideal way of using jQuery and but since we all use jQuery for different needs in a web project, it makes sense to leverage it for whatever feature we can. You can use the attr() function of jQuery to redirect a web page as shown below.
Here is a complete web page which redirects to another URL using jQuery.
<html>
<head>
<title>Redirect a webpage using jQuery</title>
</head>
<body>
<h2>Redirecting to another URL</h2>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script> $(document).ready(function() { var url = "https://web-help-technology.blogspot.com/";
$(location).attr('href',url);
});
</script>
</body>
</html>
No comments:
Post a Comment