Safari推送通知 - window.safari不存在

时间:2014-01-17 17:17:15

标签: javascript safari push-notification apple-push-notifications osx-mavericks

实施Safari Push Notifications,我试图效仿他们的例子:

// Ensure that the user can receive Safari Push Notifications.
if ('safari' in window && 'pushNotification' in window.safari) {
    ...
}

我的带有以下代码的测试HTML文件驻留在OSX 10.9.x Maverics上,我在同一台机器上的Safari 7.x中打开它。
Safari中存在通知首选项窗格,因此我假设系统支持Safari推送通知。

但是,DOM窗口对象不包含'safari',如Safari的Web Inspector中所示。因此,window.safari.pushNotification不可用 window.navigator.userAgent :Mozilla / 5.0(Macintosh; Intel Mac OS X 10_7_5)AppleWebKit / 536.30.1(KHTML,与Gecko一样)Version / 6.0.5 Safari / 536.30.1

<!DOCTYPE html>
<html>
<body>
  <script>
    window.onload = function() {
      document.getElementById("id1").innerHTML='safari' in window;
      document.getElementById("id2").innerHTML=window.safari;
    }
  </script>
  <h2>Safari Push Notifications</h2>
  <div>'safari' in window ? <span id="id1"></span></div>
  <div>window.safari ? <span id="id2"></span></div>
</body>
</html>

客户如何获得对pushNotification的访问权?

0 个答案:

没有答案