Ario.Paxaz Posted March 4, 2018 Share Posted March 4, 2018 Hi How to can Confirmation before closing of tab or browser ? Best Regards. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 4, 2018 Share Posted March 4, 2018 Hi, You can try to use this approach: MainForm -> Script: window.onbeforeunload = function() { return ""; }; https://www.w3schools.com/jsref/event_onbeforeunload.asp Quote Link to comment Share on other sites More sharing options...
andyhill Posted March 5, 2018 Share Posted March 5, 2018 Where is MainmForm Script (it is not in ClientEvents) ? I tried MyList:= TStringList.Create; MyList.Add('window.onbeforeunload = function() '); MyList.Add('{ '); MyList.Add(' return ""; '); MyList.Add('}; '); MainmForm.SetScript(MyList); MyList.Free; But fails, please advise. Quote Link to comment Share on other sites More sharing options...
Daryl McMurray Posted March 6, 2018 Share Posted March 6, 2018 Hi Andy - The TUnimForm (Mobile Form) does not have a script property, but you can accomplish the same effect by adding an event handler for the window.afterCreate event in the ClientEvents->UniEvents list. function window.afterCreate(sender) { window.onbeforeunload = function () { return ''; }; } Quote Link to comment Share on other sites More sharing options...
andyhill Posted March 6, 2018 Share Posted March 6, 2018 Thanks Daryl Quote Link to comment Share on other sites More sharing options...
andyhill Posted March 6, 2018 Share Posted March 6, 2018 OK, suggestion above on MobileForm only works in Desktop emulation mode (Chrome W10), it makes no difference in Mobile mode (Safari iPhoneX) ? Any ideas ? Quote Link to comment Share on other sites More sharing options...
Daryl McMurray Posted March 6, 2018 Share Posted March 6, 2018 Hi again Andy - I've done some digging... it looks like you may be out out of luck on this one... It seems that in the early days of the onbeforeunload implementation, it worked exactly like you would expect, but after constant abuse from unfriendly websites that would try to trap the user into staying on their page and hit them with popups, it was altered greatly, and not in the same way on every browser. see: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload "Since 25 May 2011, the HTML5 specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event. See the HTML5 specification for more details. Note also, that various browsers ignore the result of the event and do not ask the user for confirmation at all. The document will always be unloaded automatically. Firefox has a switch named dom.disable_beforeunload in about:config to enable this behaviour." Basically, if the browser supports it at all, then it will most likely ignore anything you do in the event, display its own prompt to the user and only act on the result provided by hard user input. I believe the mobile browsers for the most part ignore the event. UniGui can only do what the browsers will allow. Sorry. - As a developer who understands the desire to provide users with a safety net from accidentally closing the browser/tab and loosing data, I am saddened, but I do understand the reason it was altered. Quote Link to comment Share on other sites More sharing options...
andyhill Posted March 7, 2018 Share Posted March 7, 2018 Thanks for your time Daryl on this matter. Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted March 7, 2018 Administrators Share Posted March 7, 2018 MainModule.BackButtonAction Quote Link to comment Share on other sites More sharing options...
andyhill Posted March 7, 2018 Share Posted March 7, 2018 Thanks Farshad, but same results - works on Desktop Emulation (/m) but does not work on iPhone. Quote Link to comment Share on other sites More sharing options...
Daryl McMurray Posted March 7, 2018 Share Posted March 7, 2018 Thanks Farshad - I had actually looked into that for Andy as well... on my samsung phone, using chrome, this does indeed handle the case of the user hitting back button (though not consistently), but it doesn't help with closing the tab or browser ... I don't believe this is possible as the browser doesn't support it. UniGui can only do so much. And it makes sense... Giving an app or a website the power to not shut down when the user is instructing it to, intentionally or otherwise, is too much power. Maybe just have a warning on your main or login screen that doing so may result in lost data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.