#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    111
    Rep Power
    4

    Onbeforeunload not work on mobile browser? Any alternative?


    Hi. I've a js confirm message if a user want to leave the page. It work on pc browser but when I try to use it on mobile safari it doesn't work. And I can't find any thing from the internet. There're only a little in the net but those doesn't have a firm solution. It's more a suggestion to give a try but it's no use.

    Anyone know any alternative? Thank you.


    window.onbeforeunload = askUser ;
    function askUser(){
    return "Are you sure to exit?";
    }
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    184
    You might want to use "window.unload" for Safari, instead of "window.onbeforeunload".

    iOS Developer Library - Safari Handling Events

    Then, if needed; you might be able to use the abort() event; to prevent propagation.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    111
    Rep Power
    4
    I tried this. I did a alert or open inside and no respond. Any idea?

    $(window).unload(function() {
    window.open("http://www.google.ca");
    });

    Originally Posted by web_loone08
    You might want to use "window.unload" for Safari, instead of "window.onbeforeunload".

    iOS Developer Library - Safari Handling Events

    Then, if needed; you might be able to use the abort() event; to prevent propagation.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    111
    Rep Power
    4
    I can do onunload but I can't do abort. It seems doesn't work. My main goal is to do confirm message and if they cancel then it won't leave the page. I'm just trying to do abort but not work. Even window stop() seem not work.

    window.onunload=function() {
    window.abort();
    }


    Originally Posted by web_loone08
    You might want to use "window.unload" for Safari, instead of "window.onbeforeunload".

    iOS Developer Library - Safari Handling Events

    Then, if needed; you might be able to use the abort() event; to prevent propagation.
  8. #5
  9. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    184
    Did you try something like this?

    Code:
    window.onunload = function() {
    return confirm("Are you sure you want to leave this page?");
    }
    Because according to the Safari Web Content Guide; Safari iOS supports JavaScript dialog methods; such as: alert, confirm, print, and prompt.

IMN logo majestic logo threadwatch logo seochat tools logo