1

チャット用の Webkit デスクトップ通知を作成しました。ユーザーが現在のチャット ページ (つまり、別のタブ) にいない場合、通知を受け取ります。私がそれらを機能させたいので、すべてが正常に機能します:)

今私がする必要があるのは、ユーザーがブラウザの他のタブにある表示された通知をクリックすると、チャットタブに戻ることです。

例: ユーザーがチャットしてMyAwesomeChat.example.comから Google.com に移動し、そこで通知を受け取ります。彼が通知をクリックするとすぐに、MyAwesomeChat.example.com **

以下に、関数でコードを記述しました。上記のことをしたいところに「クリック」を追加しますaddEventListnerが、まだ無知です。

desktopnotify:(chat) ->
                if (window.webkitNotifications)
                    havePermission = window.webkitNotifications.checkPermission()
                    if havePermission is 0 && @window_blur
                      if (!(chat.get('USER_MAIL')==LOCAL_DATA.username)) 
                      # 0 is PERMISSION_ALLOWED means the user 'allow's the permission to show desktop notification when asked
                        pLength = Participants.where({USER_MAIL:chat.get('USER_MAIL')}).length
                        userImage = Participants.where({USER_MAIL:chat.get('USER_MAIL')})[pLength-1].get('USER_IMAGE')
                        
                        if(userImage?)
                          notification = window.webkitNotifications.createNotification(userImage, chat.get('USER_MAIL'), chat.get('MESSAGE'))
                          
                        else
                          notification = window.webkitNotifications.createNotification('/images/no-image.jpeg', chat.get('USER_MAIL'), chat.get('MESSAGE'))
                        notification.addEventListener('display',()->
                          window.setTimeout((e)->
                            notification.cancel()
                          , 5000)
                        notification.addEventListener('click',()->
                            console.log('here i want to do the magic. it will take back user to the page where he was chatting')
                            )  
                        )
                        notification.show()

アイデア/ヘルプ/提案をいただければ幸いです。

4

1 に答える 1

2

デフォルトでは、通知はそれをトリガーするウィンドウ/タブにバインドされます。したがって、クリック時にバインディング タブにフォーカスするように指示するだけです。

のようなものを追加

notification.onclick = function() { 
window.focus();    // focus on binding window
this.cancel();     // close the notification on clicking it
};

したがって、最終的なコードは次のようになります

    if (window.webkitNotifications)
                        havePermission = window.webkitNotifications.checkPermission()
                        if havePermission is 0 && @window_blur
                          if (!(chat.get('USER_MAIL')==LOCAL_DATA.username)) 
                          # 0 is PERMISSION_ALLOWED means the user 'allow's the permission to show desktop notification when asked
                            pLength = Participants.where({USER_MAIL:chat.get('USER_MAIL')}).length
                            userImage = Participants.where({USER_MAIL:chat.get('USER_MAIL')})[pLength-1].get('USER_IMAGE')

                            if(userImage?)
                              notification = window.webkitNotifications.createNotification(userImage, chat.get('USER_MAIL'), chat.get('MESSAGE'))

                            else
                              notification = window.webkitNotifications.createNotification('/images/no-image.jpeg', chat.get('USER_MAIL'), chat.get('MESSAGE'))
                            notification.addEventListener('display',()->
                              window.setTimeout((e)->
                                notification.cancel()
                              , 5000)
                            notification.addEventListener('click',()->
                                console.log('here i want to do the magic. it will take back user to the page where he was chatting')
                                )  
                            )

//--------------------------------------------------------------------//

                            notification.onclick = function() { 
                            window.focus();
                            this.cancel();
                            };

//--------------------------------------------------------------------//

                            notification.show()

乾杯!!

于 2013-10-11T13:27:14.483 に答える