How To Redirect A Page Or Url Using Javascript Together With Jquery
Redirecting a spider web page means, taking user to novel location. Many website utilisation redirect for many unlike reasons, e.g. Some website redirect user from sometime 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, too worked previously amongst Servlet and JSP, thence you lot mightiness hold upwards familiar amongst SendRedirect too Forward methods, which are used to redirect user inward spider web applications. Actually in that location are 2 kinds of redirect, Server side redirect too customer side redirect. In Server side redirect, server initiate redirection, piece inward 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 large theme too unlike people create it differently. e.g. bloggers by too large used platform similar WordPress, Blogger characteristic to redirect a page, though this mightiness hold upwards restricted to same domain.
In this JavaScript too jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If you lot are learning jQuery thence I likewise propose you lot to drib dead along a re-create of Head First jQuery, I bring too e'er look dorsum on this majority whenever I stuck. It has got around expert examples, which you lot tin plough over the axe e'er refer back.
You tin plough over the axe fifty-fifty overstep URL direct 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 plough over the axe overstep novel URL to replace() method too it volition copy an HTTP redirect. By the way, retrieve that window.location.replace() method doesn't pose the originating page inward session history, which may deport on behavior of dorsum button. Sometime, it's what you lot want, thence utilisation it carefully.
That's all on how to redirect a page or URL using JQuery too JavaScript. It's debatable, whether to stuck amongst JavaScript or JQuery for redirection, but if I postulate to direct betwixt both of them, I would acquire amongst jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of job on all browser, it's amend to hold upwards condom thence sorry.
Well, HTTP redirection is a large theme too unlike people create it differently. e.g. bloggers by too large used platform similar WordPress, Blogger characteristic to redirect a page, though this mightiness hold upwards restricted to same domain.
In this JavaScript too jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.
Btw,If you lot are learning jQuery thence I likewise propose you lot to drib dead along a re-create of Head First jQuery, I bring too e'er look dorsum on this majority whenever I stuck. It has got around expert examples, which you lot tin plough over the axe e'er refer back.
JQuery Code to redirect a page or URL.
Here is the JQuery code for redirecting a page. Since, I bring pose this code on $(document).ready() function, it volition execute equally shortly equally page is loaded. var url = "http://java67.blogspot.com";
$(location).attr('href',url);
You tin plough over the axe fifty-fifty overstep URL direct to attr() method, instead of using a variable.
JavaScript Code for redirecting a URL
It's fifty-fifty simpler inward JavaScript. You exclusively postulate to alter window.location.href belongings to redirect a page. Though around people likewise utilisation window.location only, which is likewise fine. If you lot are curious most departure betwixt window.location too window.location.href, thence you lot tin plough over the axe run into that subsequently i is setting href belongings explicitly, piece before i does it implicitly. Since window.location returns an object, which past times 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 plough over the axe overstep novel URL to replace() method too it volition copy an HTTP redirect. By the way, retrieve that window.location.replace() method doesn't pose the originating page inward session history, which may deport on behavior of dorsum button. Sometime, it's what you lot want, thence utilisation it carefully.
//does't pose originating page inward history
window.location.replace("http://savingsfunda.blogspot.com");
HTML Example of Redirecting a Page or URL
Here is consummate HTML page, which uses higher upwards method to redirect a page or URL. Since you lot tin plough over the axe exclusively utilisation i method at a time, I bring commented residue of code for redirection. You tin plough over the axe uncomment too effort them equally well. <!DOCTYPE html>
<html>
<head>
<title>JavaScript too 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 too JavaScript. It's debatable, whether to stuck amongst JavaScript or JQuery for redirection, but if I postulate to direct betwixt both of them, I would acquire amongst jQuery, because jQuery offers cross browser compatibility. Though, window.location.href may piece of job on all browser, it's amend to hold upwards condom thence sorry.
Belum ada Komentar untuk "How To Redirect A Page Or Url Using Javascript Together With Jquery"
Posting Komentar