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
https://forums.phpfreaks.com/topic/269226-confirm-box-issue-on-safari/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.