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 usage redirect for many dissimilar reasons, e.g. Some website redirect user from sometime domain to novel domain, about redirect from ane page to about other e.g. a to a greater extent than relevant page. If you lot are Java programmer, together with worked previously amongst Servlet and JSP, together with therefore you lot mightiness survive familiar amongst SendRedirect together with Forward methods, which are used to redirect user inwards spider web applications. Actually in that location are 2 kinds of redirect, Server side redirect together with 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 together with dissimilar people create it differently. e.g. bloggers to a greater extent than ofttimes than non used platform similar WordPress, Blogger characteristic to redirect a page, though this mightiness survive restricted to same domain.

In this JavaScript together with jQuery tutorial, nosotros volition larn a novel JQuery tip to redirect a page.

Btw,If you lot are learning jQuery together with therefore I likewise advise you lot to proceed a re-create of Head First jQuery, I accept together with ever  look dorsum on this mass whenever I stuck. It has got about skillful examples, which you lot tin ever refer back.


JQuery Code to redirect a page or URL.

Here is the JQuery code for redirecting a page. Since, I accept position 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 fifty-fifty transcend URL direct to attr() method, instead of using a variable.




JavaScript Code for redirecting a URL

 Many website usage redirect for many dissimilar reasons How to redirect a page or URL using JavaScript together with JQueryIt's fifty-fifty simpler inwards JavaScript. You solely postulate to alter window.location.href belongings to redirect a page. Though about people likewise usage window.location only, which is likewise fine. If you lot are curious most departure betwixt window.location together with window.location.href, together with therefore you lot tin run across that afterward ane is setting href belongings explicitly, piece before ane 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 transcend novel URL to replace() method together with it volition imitate an HTTP redirect. By the way, retrieve that window.location.replace() method doesn't position the originating page inwards session history, which may conduct on demeanour of dorsum button. Sometime, it's what you lot want, therefore usage it carefully.

//does't position 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 solely usage ane method at a time, I accept commented residue of code for redirection. You tin uncomment together with endeavour them equally well.

<!DOCTYPE html>
<html>
        <head>
                <title>JavaScript together with 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 together with 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 occupation on all browser, it's ameliorate to survive condom together with therefore sorry.


Sumber https://javarevisited.blogspot.com/

2 Responses to "How To Redirect A Page Or Url Using Javascript Together With Jquery"

  1. "Changing a current area or subdomain to divert
    Explore to the Manage Domains page. ...
    Snap the Edit button situated to one side of the area/subdomain under the Web Hosting segment.
    Look down to the Redirect segment. ...
    In the 'Divert to URL' field enter the URL where you'd like this space to divert."
    for more information click here: HOW TO REDIRECT A DOMAIN TO ANOTHER SITE

    ReplyDelete

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel