CaptainChainsaw Posted October 8, 2012 Share Posted October 8, 2012 Hi all, I've got a problem with this piece of code. I believe this should work properly but when closing the Safari browser the alert box is properly displayed but when clicking "Ok" the browser closes. It should return to the page as it returns false. I've tried setting it to return false but with no luck. This works on FF and Chrome ok. var is_chrome = navigator.userAgent.indexOf('Chrome') > -1; var is_explorer = navigator.userAgent.indexOf('MSIE') > -1; var is_firefox = navigator.userAgent.indexOf('Firefox') > -1; var is_safari = navigator.userAgent.indexOf("Safari") > -1; var is_Opera = navigator.userAgent.indexOf("Presto") > -1; if ((is_chrome)&&(is_safari)) {is_safari=false;} //within $(document).ready(function(){ jQuery(window).bind("beforeunload", function(){ // showDebug1("Exiting..."); $.ajax({ url: "<?=$exit_url?>"}); leave = confirm("Exit page?"); if (leave==true){ return ret; } else { if(is_chrome) { return 'Leave page?'; } else if(is_safari) { alert('Click OK to continue'); } else { return false; } } }); Anyone have any ideas? Cheers, CaptainChainsaw Quote Link to comment Share on other sites More sharing options...
CaptainChainsaw Posted October 8, 2012 Author Share Posted October 8, 2012 Got this fixed. Adding in this code got it working: else if(is_safari) { return 'Leave page?'; } Quote Link to comment Share on other sites More sharing options...
Adam Posted October 8, 2012 Share Posted October 8, 2012 Just as an FYI, this form of browser matching is completely useless. You're able to detect an IE user with is_explorer for example, but how do you do know if they're using IE5 or IE10? The only thing those two browsers have in common is the name "Internet Explorer", branding them the same browser is going to cause you headaches later on. You should take a look into feature detection. 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.