1

I'm quite desperate due to the following issue: How the hell :-) .. can I force my page to be reloaded everytime so lands on it? I have a input which is automatically filled with text from localStorage if this value is set. And I have links on my page to other pages. So (just an example) maybe the user clicks on pagexyz.com and then decides to navigate back to my site by clicking the backbutton. I tried a whole lot of things but am not able to force my piece of javascript to be executed.

The solution given here did not help me around.

These did not help.

So what else to do? I tried setting all cache-related meta tags - there must be a way to execute js when the page is called!?

So thankful for any kind of hint! hos

Community
  • 1
  • 1
ho.s
  • 751
  • 3
  • 17
  • 42
  • I see no reason why the Question in your statement "These did not help." would not work for you? *Why* didn't it work when you tried it? – SpaceBison Feb 16 '12 at 09:45
  • Looks like you are trying to reset you form? http://stackoverflow.com/questions/680241/resetting-a-multi-stage-form-with-jquery – Roko C. Buljan Feb 16 '12 at 09:54
  • @SpaceBison: I think because all the script and onload stuff is just NOT executed – ho.s Feb 16 '12 at 10:14

1 Answers1

1

The problem is that by navigating back with the back button of the browser, the onload event of the page usually does not fire, neither will the JS code in the global scope be executed.

One possible solution that is widely used for the so-called "hash history hack": Start an interval with setInterval() that checks every (let's say) 500 msec for a hash change and refresh the content according to the hash.

On a usual content refresh you'll have to set the hash manually (window.location.hash="..."). And on initial page load (perhaps from a bookmark) you'll have to check the window.location.hash and load content accordingly.

devnull69
  • 16,402
  • 8
  • 50
  • 61
  • you saved my day, thanks a lot! i implemented a setInterval-method *even in between my $(document).ready* and test for the value of my input text. if its empty i fill in with the localStorage text. when i now land from google or whereever by backbutton this method always is executed and i stop it when the value is set. great! now i just try to understand: why is the setInterval-function always executed but no other piece of js i tried? – ho.s Feb 16 '12 at 10:56
  • all the event handlers will still work (so e.g. clicking a button will still trigger the corresponding method), and the setInterval function is just another event handler ... automatically instead of manually triggered, but still – devnull69 Feb 16 '12 at 11:58
  • thank you so very much. i should have known that or come to that, but.. was a blockhead :-) – ho.s Feb 16 '12 at 12:26