Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Chrome中的HMTL5桌面通知问题_Javascript_Google Chrome_Notifications - Fatal编程技术网

Javascript Google Chrome中的HMTL5桌面通知问题

Javascript Google Chrome中的HMTL5桌面通知问题,javascript,google-chrome,notifications,Javascript,Google Chrome,Notifications,我在向wicket站点添加基本桌面通知时遇到问题。基于上的示例代码,我已在页面中重写renderHead(IHeaderResponse)方法,以便在页面中添加以下内容: <script type="text/javascript" id="desktopNotification-init"> /*<![CDATA[*/ function notifyMe(){ if (!("Notification" in window)) { alert("

我在向wicket站点添加基本桌面通知时遇到问题。基于上的示例代码,我已在页面中重写renderHead(IHeaderResponse)方法,以便在页面中添加以下内容:

<script type="text/javascript" id="desktopNotification-init">
  /*<![CDATA[*/
  function notifyMe(){ 
    if (!("Notification" in window)) { 
      alert("This browser does not support desktop notification"); 
    }else if (Notification.permission === "granted") { 
      var notification = new Notification("You have a system notification"); 
    }else if (Notification.permission !== 'denied') { 
      Notification.requestPermission(function (permission) { 
        if(!('permission' in Notification)) { 
          Notification.permission = permission; 
        } 
        if (permission === "granted") { 
          var notification = new Notification("You have a system notification"); 
        } 
     }); 
    } 
  }

/*]]>*/
</script>
这在Firefox中有效,但在Chrome中单击按钮无效。这似乎是权限请求的一个问题,因为如果我更改设置以始终允许通知,它将正常工作。我缺少的javascript有问题吗

public void onClick( AjaxRequestTarget p_target, WebMarkupContainer p_menuItemComponent ) {
    if( p_target != null  ) {
      p_target.appendJavaScript( "notifyMe();" );
    }
}