最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I make a Notification stay open until the user closes it? - Stack Overflow

programmeradmin2浏览0评论

Is there a setting that will allow me to keep a Notification open until a user clicks it?

                      if (("Notification" in window)) {

                          Notification.requestPermission(function() {
                                var notification = 
                                    new Notification('Hello', 
                                        { 
                                            body : 'Hello',
                                            icon: '.png',
                                            tag: 'Test' ,
                                        });

                                    notification.onclick    = function(event) {
                                      event.preventDefault(); // prevent the browser from focusing the Notification's tab
                                      window.open('', '_blank');
                                    }
                                            window.navigator.vibrate(500);
                            });
                      }

Is there a setting that will allow me to keep a Notification open until a user clicks it?

                      if (("Notification" in window)) {

                          Notification.requestPermission(function() {
                                var notification = 
                                    new Notification('Hello', 
                                        { 
                                            body : 'Hello',
                                            icon: 'https://www.domain./images/live_chat_icon.png',
                                            tag: 'Test' ,
                                        });

                                    notification.onclick    = function(event) {
                                      event.preventDefault(); // prevent the browser from focusing the Notification's tab
                                      window.open('https://www.domain.', '_blank');
                                    }
                                            window.navigator.vibrate(500);
                            });
                      }
Share Improve this question asked Sep 23, 2016 at 15:41 PatrickPatrick 2,5771 gold badge21 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

According to the docs there is a boolean requireInteraction:

A Boolean indicating that on devices with sufficiently large screens, a notification should remain active until the user clicks or dismisses it. https://developer.mozilla/en-US/docs/Web/API/notification

new Notification('Hello', { 
   body : 'Hello', 
   requireInteraction: true 
});

Tested in Chrome on MacOS.

发布评论

评论列表(0)

  1. 暂无评论