Jump to content

Confirm Box Issue On Safari


CaptainChainsaw

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.