0

I have problem with onbeforeunload and preventing user from exit the page: When user want to exits i want to redirect him on other page, without any warning or pop-up

I try to popUp that page, but browser popup detect this and block it.

Is something like that possible?

Have a nice day!

freska
  • 1
  • 2
  • 5
    It may be possible, sometimes, on some browsers. It's just *really, really, really* irritating. Do you have a use-case that isn't...evil? ;-) – T.J. Crowder Mar 03 '11 at 14:54
  • 3
    Cannot agree more with T.J. - I'm not sure sharing the answer here is a good investment in the future of the internet :P – Martin Jespersen Mar 03 '11 at 14:58
  • 1
    Think if this was possible, a developer could force their page open on your machine for eternity or until MS blue screens. – epascarello Mar 03 '11 at 15:00

3 Answers3

3

Browsers disallow that sort of behavior since it's normally a very unpleasant thing for the user.

Marcus Frödin
  • 12,552
  • 3
  • 25
  • 16
0

Yes, i know this is unpleasant, but it is mainly internal page, so it is targeted group of users ( i hate popups to). One way i found was just redirect user on other page with message "are you realy want to leave page" (of course he want if he go away, but this is some strange fSpec)

freska
  • 1
-2

You can use this code: window.onbeforeunload = function() { return "MyMessage"; }

almar
  • 27
  • 2