How To Redirect A Page Or Url Using Javascript As Well As Jquery
Redirecting a spider web page means, taking user to novel location. Many website job redirect for many dissimilar reasons, e.g. Some website redirect user from quondam domain to novel domain, about redirect from i page to about other e.g. a to a greater extent than relevant page. If y'all are Java programmer, in addition to worked previously alongside Servlet and JSP, in addition to thus y'all mightiness endure familiar alongside SendRedirect in addition to Forward methods, which are used to redirect user inwards spider web applications. Actually at that spot are 2 kinds of redirect, Server side redirect in addition to customer side redirect. In Server side redirect, server initiate redirection, piece inwards customer side redirect, customer code does the redirection. Redirecting a spider web page using JavaScript and JQuery is a client side redirection.
Well, HTTP redirection is a big topic in addition to dissimilar people create it differently. e.g. bloggers to a greater extent than oftentimes than non used platform similar WordPress, Blogger characteristic to redirect a page, though this mightiness endure restricted to same domain.
In this JavaScript in addition to jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If y'all are learning jQuery in addition to thus I likewise propose y'all to proceed a re-create of Head First jQuery, I accept in addition to ever look dorsum on this majority whenever I stuck. It has got about skillful examples, which y'all tin flame ever refer back.
You tin flame fifty-fifty exceed URL straight to attr() method, instead of using a variable.
It's fifty-fifty simpler inwards JavaScript. You entirely quest to modify window.location.href belongings to redirect a page. Though about people likewise job window.location only, which is likewise fine. If y'all are curious close divergence betwixt window.location in addition to window.location.href, in addition to thus y'all tin flame run across that afterwards i is setting href belongings explicitly, piece before i does it implicitly. Since window.location returns an object, which yesteryear default sets it's .href property.
There is about other way to redirect a page using JavaScript, replace() method of window.location object. You tin flame exceed novel URL to replace() method in addition to it volition copy an HTTP redirect. By the way, cry back that window.location.replace() method doesn't lay the originating page inwards session history, which may touching behavior of dorsum button. Sometime, it's what y'all want, thus job it carefully.
That's all on how to redirect a page or URL using JQuery in addition to JavaScript. It's debatable, whether to stuck alongside JavaScript or JQuery for redirection, but if I quest to select betwixt both of them, I would acquire alongside jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of work on all browser, it's amend to endure condom in addition to thus sorry.
Well, HTTP redirection is a big topic in addition to dissimilar people create it differently. e.g. bloggers to a greater extent than oftentimes than non used platform similar WordPress, Blogger characteristic to redirect a page, though this mightiness endure restricted to same domain.
In this JavaScript in addition to jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If y'all are learning jQuery in addition to thus I likewise propose y'all to proceed a re-create of Head First jQuery, I accept in addition to ever look dorsum on this majority whenever I stuck. It has got about skillful examples, which y'all tin flame ever refer back.
JQuery Code to redirect a page or URL.
Here is the JQuery code for redirecting a page. Since, I accept lay this code on $(document).ready() function, it volition execute equally presently equally page is loaded. var url = "http://java67.blogspot.com";
$(location).attr('href',url);
You tin flame fifty-fifty exceed URL straight to attr() method, instead of using a variable.
JavaScript Code for redirecting a URL
It's fifty-fifty simpler inwards JavaScript. You entirely quest to modify window.location.href belongings to redirect a page. Though about people likewise job window.location only, which is likewise fine. If y'all are curious close divergence betwixt window.location in addition to window.location.href, in addition to thus y'all tin flame run across that afterwards i is setting href belongings explicitly, piece before i does it implicitly. Since window.location returns an object, which yesteryear default sets it's .href property. //similar to window.location
window.location.href="http://java67.blogspot.com";
There is about other way to redirect a page using JavaScript, replace() method of window.location object. You tin flame exceed novel URL to replace() method in addition to it volition copy an HTTP redirect. By the way, cry back that window.location.replace() method doesn't lay the originating page inwards session history, which may touching behavior of dorsum button. Sometime, it's what y'all want, thus job it carefully.
//does't lay originating page inwards history
window.location.replace("http://savingsfunda.blogspot.com");
HTML Example of Redirecting a Page or URL
Here is consummate HTML page, which uses inwards a higher house method to redirect a page or URL. Since y'all tin flame entirely job i method at a time, I accept commented residuum of code for redirection. You tin flame uncomment in addition to seek them equally well. <!DOCTYPE html>
<html>
<head>
<title>JavaScript in addition to JQuery Example to Redirect a page or URL </title>
</head>
<body>
<div id="redirect">
<h2>Redirecting to about other Page</h2>
</div>
<script src="scripts/jquery-1.6.2.min.js"></script>
<script>
// JavaScript code to redirect a URL
window.location.replace("http://java67.blogspot.com");
// Another way to redirect page using JavaScript
//window.location.href="http://java67.blogspot.com";
//JQuery code to redirect a page or URL
$(document).ready(function(){
/var url = "http://java67.blogspot.com";
//$(location).attr('href',url);
});
</script>
</body>
</html>
That's all on how to redirect a page or URL using JQuery in addition to JavaScript. It's debatable, whether to stuck alongside JavaScript or JQuery for redirection, but if I quest to select betwixt both of them, I would acquire alongside jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of work on all browser, it's amend to endure condom in addition to thus sorry.
Komentar
Posting Komentar