我正在尝试在我的网站中集成Safari推送通知。我拿了Apple的代码并在我的简单测试网站上设置了所有内容。当我在Mavericks 10.9上的Safari 7上试用它时,控制台说我没有使用Safari。
这里发生了什么?
代码:
<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>
答案 0 :(得分:1)
window.onload = function() {
if(window.navigator.userAgent.indexOf('7.0 Safari') > -1) {
checkPerms();
}
else {
//Handle other browsers!!!
}
答案 1 :(得分:0)
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!!!
}
} }