0

i got a simple onbeforeunload function but I'm seeing that is being fired everytime, even when log out. Is there any chance to avoid from firing when log out?

Thanks.

msqar
  • 2,940
  • 5
  • 44
  • 90

1 Answers1

1

You can add Conditions before you Call your window.onbeforeunload

  if(condition && condition)
   {
    window.onbeforeunload = function(e) {
    return 'Dialog text here.';
    };
   }
Alaeddine
  • 1,571
  • 2
  • 22
  • 46
  • yea, makes sense! nice idea :) going to see how i perform it and let you know but it might work! – msqar Apr 15 '14 at 15:56
  • Yea made it work, but do you know why it doesn't work in Firefox 28? like the dialog is always showing up in Firefox. I made something else on this, i added the validation inside the onbeforeunload function if the logout was clicked or not. It works in chrome and IE, but not in FF – msqar Apr 15 '14 at 19:37
  • I don't know exactly but In FireFox you need to use it like this `if (e) { e.returnValue = 'Any string';}` check this [LINK](http://stackoverflow.com/questions/3727216/window-onbeforeunload-support-in-firefox) and don't forget to check that Answer :p – Alaeddine Apr 15 '14 at 19:44
  • 1
    No, i made it work :) is just i don't want to return any other custom comment tho, but i was using event.preventDefault() and that didn't work in FF, i had to do a simple "return;" if the logout was clicked. That worked for all the browsers now, thanks also for your guidance :) – msqar Apr 15 '14 at 20:09