1

I found some article in stack overflow about browser bfcache, I test in safari Version 7.0.5 (9537.77.4), when I click history back the js won't execute, How to use window.onunload or other method, handle js if not execute due to cache, make it execute?

window.onunload = function(){
  alert('window.unload');
};

$(document).ready(function(){
    // js app
});
user1775888
  • 3,147
  • 13
  • 45
  • 65
  • have you tried using `window.addEventListener` as detailed [here](https://developer.mozilla.org/en-US/docs/Web/API/Window.onunload)? – mechalynx Jul 22 '14 at 02:48
  • yes, I saw this reference, but I can't understand how to combine to use? Can you show example for me? – user1775888 Jul 22 '14 at 02:49
  • if you'd bothered to click the link to the `addEventListener` reference page, you'd see an example. there should also be plenty online. – mechalynx Jul 22 '14 at 02:54
  • I'm confusing should I put my application into unload callback? – user1775888 Jul 22 '14 at 02:55
  • Of course not! The whole point is, you attach the event handler through the DOM event system instead of the node properties. It is the recommended way to do it and it should work better. there's even an answer with this exact thing ffs! – mechalynx Jul 22 '14 at 02:57
  • ?? so how do I make if click history js not execute, force to execute? – user1775888 Jul 22 '14 at 02:59

1 Answers1

-1

Use:

window.addEventListener('unload', function(){
  alert('window.unload');
}); 
Sarbbottam
  • 5,410
  • 4
  • 30
  • 41