I'm redesigning my site to use a new tab control widget I have built.
The problem I have is the widget not remembering what tab was active should the user click a link from the widget, then use the browser back button.
Doing some investigating last night, I found it is a major issue, as $(document).ready fires all the time in Chrome when back is clicked but not in FireFox.
Apparently FireFox uses a BFCache (Back/Forward Cache), so it remembers DOM state and so doesn't re-trigger $(document).ready. I've tried $(window).load but again doesn't re-fire in FireFox either.
What I have found is this thread :
So I have implemented this
Which from my initial Linux tests does force FireFox to rerun $(document).ready (yet to test on Windows & IE).
So I now have my widget rendering routine, which uses cookies to store widget state as well as load widget state, which works perfectly.
However, I would rather if possible allow browsers that have a BFCache to use it, so some of my AJAX calls requesting JSON don't keep firing, as there is no need to keep making these http requests once the data has been retrieved the first time.
So although using my current 'hack' solves some of my problems, it creates others.
So is this currently the only way to get JavaScript to fire every time the page is rendered whether being reached via a direct landing page or the browser back button.
I was considering using a cookie to store the fact the page was initially loaded, and then using this as a flag for if certain code needs to run again.
How do you deal with JQuery apps and browser back buttons?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
The problem I have is the widget not remembering what tab was active should the user click a link from the widget, then use the browser back button.
Doing some investigating last night, I found it is a major issue, as $(document).ready fires all the time in Chrome when back is clicked but not in FireFox.
Apparently FireFox uses a BFCache (Back/Forward Cache), so it remembers DOM state and so doesn't re-trigger $(document).ready. I've tried $(window).load but again doesn't re-fire in FireFox either.
What I have found is this thread :
So I have implemented this
Code:
jQuery(window).bind("unload", function(){));
Which from my initial Linux tests does force FireFox to rerun $(document).ready (yet to test on Windows & IE).
So I now have my widget rendering routine, which uses cookies to store widget state as well as load widget state, which works perfectly.
However, I would rather if possible allow browsers that have a BFCache to use it, so some of my AJAX calls requesting JSON don't keep firing, as there is no need to keep making these http requests once the data has been retrieved the first time.
So although using my current 'hack' solves some of my problems, it creates others.
So is this currently the only way to get JavaScript to fire every time the page is rendered whether being reached via a direct landing page or the browser back button.
I was considering using a cookie to store the fact the page was initially loaded, and then using this as a flag for if certain code needs to run again.
How do you deal with JQuery apps and browser back buttons?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music