BalestraPatrick
BalestraPatrick

Reputation: 10144

Safari Push Notifications - Javascript not checking browser correctly

I am trying to integrate Safari Push Notifications in my website. I took Apple's code and set up everything in my simple test website. When I try it on my Safari 7 on Mavericks 10.9, the console says that I am not using Safari.

What's going on here?

Code:

<script type="text/javascript">

if ('safari' in window && 'pushNotification' in window.safari) {
    var permissionData = window.safari.pushNotification.permission('web.com.example.website');
    checkRemotePermission(permissionData);
}
else {
    console.log('Push Notifications are available for Safari browser only');
}
</script>

Upvotes: 1

Views: 589

Answers (2)

itsEssa
itsEssa

Reputation: 11

window.onload = function() {
    //for future versions of safari 
    var ua = window.navigator.userAgent,
    safari = ua.indexOf ( "Safari" ),
    version = ua.substring(0,safari).substring(ua.substring(0,safari).lastIndexOf("/")+1);

    if(safari > 0 && parseInt(version) >=7) {
    checkPerms();
    }
    else {
    //Handle other browsers!!!
    }
        }                    }

Upvotes: 0

Peder Naalsund
Peder Naalsund

Reputation: 11

window.onload = function() {
if(window.navigator.userAgent.indexOf('7.0 Safari') > -1) {
    checkPerms();
}
else {
    //Handle other browsers!!!
}

Upvotes: 1

Related Questions