Problem with back button and AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marfola
    New Member
    • Nov 2007
    • 13

    Problem with back button and AJAX

    I have an Ajax application and I want to take control of the back button. I have implemented a Javascript, but it runs correctly only on Firefox. In IE7 I got some problems.

    My script runs as follow:
    - when I click from a tab to another of the same page I update the sub-content via Ajax and I change my url adding hash parameters (using window.location .hash).
    - when I get an url with hash parameters I parse it and I send the correct sub-content to the page.

    Everything manage correctly in Firefox. If I click on the browser back button I can always get the right url (with hash parameters), then I parse it and send the correct sub-content to the page.

    In I.E. 7.0 if I click from a tab to another of the same page, the history browser doesn't push nothing. It contains always the first entry of my page (without hash parameters), while the browser bookmark got the correct url.

    Could someone help me to find the problem?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you post your code or a link to a test page that demonstrates the problem?

    Comment

    • marfola
      New Member
      • Nov 2007
      • 13

      #3
      Here's my code:

      [CODE=javascript]var lastSavedHash = "";

      /* function called when user click on tab AJAX button */
      function makeHash(mode)
      {
      window.location .hash = mode;
      lastSavedHash = window.location .hash;
      return true;
      }

      /* function who checks the hash values and send the correct sub-content to the page.*/
      function handleHash()
      {
      if ( window.location .hash != lastSavedHash )
      {
      currentHash = window.location .hash;

      mode = lastSavedHash.r eplace("#", "");

      url = window.location .href;
      querytext = url.split("/");

      if (mode != querytext[5])
      <callAjaxUpdate SubContent(mode )>;
      }
      else
      return '';
      }


      /* function called onload event and every x seconds Call handleHash function*/
      function checkHash() {
      handleHash();
      setInterval("ha ndleHash()", 200);
      }[/CODE]
      Last edited by acoder; Nov 28 '07, 09:36 AM. Reason: edited code

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        How do you call makeHash()?

        Comment

        • marfola
          New Member
          • Nov 2007
          • 13

          #5
          I call makeHash in the getAjaxContent function, i.e. every time the sub-content change after user click on a tab button.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            This is an old article, but it might help explain IE's bug.

            Comment

            • viswaj
              New Member
              • Jan 2008
              • 3

              #7
              I've also same doubt...
              Plz send the source code for currently working prog in Mozilla asap........
              Plz help me...
              I'll try and send the code to u...

              Comment

              • viswaj
                New Member
                • Jan 2008
                • 3

                #8
                can u post u r code as soon as possible...

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by viswaj
                  can u post u r code as soon as possible...
                  Have you checked out the linked article (post #6)?

                  Please try to use full English when you post, not SMS-speak. Thanks!

                  Comment

                  Working...