Javascript Google Chrome中的HMTL5桌面通知问题
我在向wicket站点添加基本桌面通知时遇到问题。基于上的示例代码,我已在页面中重写renderHead(IHeaderResponse)方法,以便在页面中添加以下内容: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("
<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();" );
}
}