By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,649 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Problem with back button and AJAX

P: 13
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?
Nov 27 '07 #1
Share this Question
Share on Google+
8 Replies


acoder
Expert Mod 15k+
P: 16,027
Can you post your code or a link to a test page that demonstrates the problem?
Nov 27 '07 #2

P: 13
Here's my code:

Expand|Select|Wrap|Line Numbers
  1. var lastSavedHash = "";
  2.  
  3. /* function called when user click on tab AJAX button */
  4. function makeHash(mode)
  5. {
  6.     window.location.hash = mode;
  7.      lastSavedHash = window.location.hash;
  8.     return true;
  9. }
  10.  
  11. /* function who checks the hash values and send the correct sub-content to the page.*/
  12. function handleHash()
  13. {
  14.   if ( window.location.hash != lastSavedHash )
  15.   {
  16.     currentHash = window.location.hash;
  17.  
  18.     mode = lastSavedHash.replace("#", "");
  19.  
  20.     url = window.location.href;
  21.     querytext = url.split("/"); 
  22.  
  23.     if (mode != querytext[5])
  24.         <callAjaxUpdateSubContent(mode)>;
  25.   }
  26.     else
  27.         return '';
  28. }
  29.  
  30.  
  31. /* function called onload event and every x seconds  Call handleHash function*/
  32. function checkHash() {
  33.     handleHash();
  34.     setInterval("handleHash()", 200);
  35. }
Nov 28 '07 #3

acoder
Expert Mod 15k+
P: 16,027
How do you call makeHash()?
Nov 28 '07 #4

P: 13
I call makeHash in the getAjaxContent function, i.e. every time the sub-content change after user click on a tab button.
Nov 28 '07 #5

acoder
Expert Mod 15k+
P: 16,027
This is an old article, but it might help explain IE's bug.
Nov 29 '07 #6

P: 3
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...
Jan 29 '08 #7

P: 3
can u post u r code as soon as possible...
Jan 29 '08 #8

acoder
Expert Mod 15k+
P: 16,027
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!
Jan 29 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.