8

I don´t really find an answer of my question, if it´s possible to detect by jquery if a user klick on the "Refresh/Reload Button" on a modern browser?

I found ...

window.onbeforeunload = function(e) {
    // Action
};

... but the problem at this way is, that it always fires if the page gets loaded. But if I use the forward button and then the back button it should not do this, only at pressing the refresh button. Is that possible? And is there a solution for all modern browsers?

Edit: Thx for the link, I will try the cookie example.

Pepe
  • 960
  • 9
  • 21
  • AFAIK, no, there is no way to detect specifically the click on refresh button. Maybe you could explain why you would need that?! – A. Wolff Aug 05 '15 at 08:14
  • I have some input fields (dropdown) which are cached by the browser on refresh and that makes an error at my script - but thx for the link, I will try it! – Pepe Aug 05 '15 at 08:19
  • So instead, ask question regarding this error, not the workaround you think would fix it. – A. Wolff Aug 05 '15 at 08:24
  • How about checking if the page refreshed (after) it refreshes.. – davidcondrey Aug 05 '15 at 08:24

1 Answers1

-2
window.onunload = function(){
  alert("unload event detected!");
}

Onload fires before window refreshes actually.

or for key detection

$("body").keydown(function (e)
    {
   if (e.which == 116 || e.which == 17) {
     inFormOrLink = true;
   }
});
Bilal
  • 265
  • 8
  • 20