Redirecting a spider web page means, taking user to novel location. Many website usage redirect for many unlike reasons, e.g. Some website redirect user from quondam domain to novel domain, around redirect from i page to around other e.g. a to a greater extent than relevant page. If you lot are Java programmer, as well as worked previously alongside Servlet and JSP, thence you lot powerfulness survive familiar alongside SendRedirect as well as Forward methods, which are used to redirect user inwards spider web applications. Actually at that topographic point are 2 kinds of redirect, Server side redirect as well as customer side redirect. In Server side redirect, server initiate redirection, land 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 theme as well as unlike people produce it differently. e.g. bloggers generally used platform similar WordPress, Blogger characteristic to redirect a page, though this powerfulness survive restricted to same domain.
In this JavaScript as well as jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If you lot are learning jQuery thence I too advise you lot to proceed a re-create of Head First jQuery, I accept as well as ever look dorsum on this majority whenever I stuck. It has got around proficient examples, which you lot tin hand the sack ever refer back.
You tin hand the sack fifty-fifty exceed URL straight to attr() method, instead of using a variable.
There is around other way to redirect a page using JavaScript, replace() method of window.location object. You tin hand the sack exceed novel URL to replace() method as well as it volition copy an HTTP redirect. By the way, holler upwardly that window.location.replace() method doesn't set the originating page inwards session history, which may comport on demeanour of dorsum button. Sometime, it's what you lot want, thence usage it carefully.
That's all on how to redirect a page or URL using JQuery as well as JavaScript. It's debatable, whether to stuck alongside JavaScript or JQuery for redirection, but if I ask to conduct betwixt both of them, I would become alongside jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of employment on all browser, it's amend to survive security thence sorry.
Well, HTTP redirection is a big theme as well as unlike people produce it differently. e.g. bloggers generally used platform similar WordPress, Blogger characteristic to redirect a page, though this powerfulness survive restricted to same domain.
In this JavaScript as well as jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If you lot are learning jQuery thence I too advise you lot to proceed a re-create of Head First jQuery, I accept as well as ever look dorsum on this majority whenever I stuck. It has got around proficient examples, which you lot tin hand the sack ever refer back.
JQuery Code to redirect a page or URL.
Here is the JQuery code for redirecting a page. Since, I accept set 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 hand the sack 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 solely ask to modify window.location.href holding to redirect a page. Though around people too usage window.location only, which is too fine. If you lot are curious most divergence betwixt window.location as well as window.location.href, thence you lot tin hand the sack run into that after i is setting href holding explicitly, land 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 around other way to redirect a page using JavaScript, replace() method of window.location object. You tin hand the sack exceed novel URL to replace() method as well as it volition copy an HTTP redirect. By the way, holler upwardly that window.location.replace() method doesn't set the originating page inwards session history, which may comport on demeanour of dorsum button. Sometime, it's what you lot want, thence usage it carefully.
//does't set 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 to a higher house method to redirect a page or URL. Since you lot tin hand the sack solely usage i method at a time, I accept commented residual of code for redirection. You tin hand the sack uncomment as well as travail them equally well. <!DOCTYPE html>
<html>
<head>
<title>JavaScript as well as JQuery Example to Redirect a page or URL </title>
</head>
<body>
<div id="redirect">
<h2>Redirecting to around 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 as well as JavaScript. It's debatable, whether to stuck alongside JavaScript or JQuery for redirection, but if I ask to conduct betwixt both of them, I would become alongside jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of employment on all browser, it's amend to survive security thence sorry.