0

I want a simple thing, but I am not getting it to work

Just like the browser change the confirmation text from

"Are you sure you want to leave this page?"

to

"Are you sure you want to reload this page?"

depending what you are doing, I want that my custom confirmation text also knows which action the user is performing.

Currently I have this:

window.onbeforeunload = function (event) {
    var infoText = (event.srcElement == event.target) ? "Reloading" : "Movig from";
    infoText += " this page will cause you to lose current information.";
    return infoText;
};

I thought that comparing the event.srcElement vs. event.target will be enough as they have the navigation links. But that if statement always returns true, so it always looks like it is reloading even if the destination link is different.

As the browser knows, I thinks there must be some way to do it. If not, I'll have to create a generic message. (Obviously I could make it generic and... done. But now I really want to know it.)

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Patrick Bard
  • 1,804
  • 18
  • 40
  • i dont think your code can know that. – Daniel A. White Jun 24 '15 at 16:13
  • By "your" you mean what I have or what I could have? The former I agree, as stated on the question... – Patrick Bard Jun 24 '15 at 16:15
  • The thing that bugs me is why the `URL` inside `event.target` does not change when I move to a different page. If I not getting its purpose wrong, it should to me... – Patrick Bard Jun 24 '15 at 16:17
  • a pretty dirty attemp would be a keydown eventlistener on the whole dom that checks for the f5 key. You could utilize this example http://jsfiddle.net/SpYk3/C85Hs/ – Mx. Jun 24 '15 at 16:18

0 Answers0