English 中文(简体)
GWT, 带有超文本5式桌面通知(网站通知)
原标题:GWT with HTML5 desktop notifications (webkitNotifications)

I am trying to implement HTML5 desktop notifications using GWT. Currently this is not supported with the GWT libraries, so I am using native javascript from within GWT(JSNI). I thought this would be fairly straight forward, however I am not having any success. I am using chrome and have tried in dev mode and a deployed app. Below is the code that I am using.

NOTE: the javascript code came from http://playground.html5rocks.com/#simple_notifications and it worked fine in chrome.

是否有人去做?

 public native void requestPermission() /*-{
         $wnd.webkitNotifications.requestPermission();      
     }-*/;

  public native void createJSNotification(String iconUrl, String title, String body) /*-{
    $wnd.webkitNotifications.createNotification(iconUrl, title, body).show();
}-*/;
最佳回答

很好,你对我看上了不起。 我尝试了这个例子,并把它带上了WT,并做了工作。 我注意到的唯一一件事是,在通知表明你是否在《规则》中行事之前可以需要一段时间:

Here is my GWT code:

public void onModuleLoad() {
    {
        Button bt_Permission = new Button("Request Permission");
        bt_Permission.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                requestPermission();
            }
        });
        RootPanel.get().add(bt_Permission);
    }
    {
        Button bt_ShowNotification = new Button("Show Notification");
        bt_ShowNotification.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                showNotification();
            }
        });
        RootPanel.get().add(bt_ShowNotification);
    }
}

public native void requestPermission() /*-{
    $wnd.webkitNotifications.requestPermission();
}-*/;

public native void  showNotification() /*-{
    var text =  You got a new email from [email protected] 
    if ($wnd.webkitNotifications.checkPermission() == 0) {
        // note the show()
        $wnd.webkitNotifications.createNotification(  ,
                 Plain Text Notification , text).show();
    } else {
        alert( You have to click on "Set notification permissions for this page" first to be able to receive notifications. );
    }
}-*/;
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签