Firefox桌面通知在多个选项卡打开时不显示 [英] Firefox Desktop Notifications not showing when multiple tabs are open

查看:200
本文介绍了Firefox桌面通知在多个选项卡打开时不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 Web通知我的意思是

更新1 :
由于hub方法被调用,我认为它不是signalr问题。

这行在所有标签上被调用:
console.log('hub the method method called sucessfully');

和signalr logging说:

p $ p $ SignalR:调用myhub.Send jquery.signalR-2.2。 1.min.js
SignalR:在集线器'MyHub'上触发客户端集线器事件'addNewMessageToPage'。 jquery.signalR-2.2.1.min.js
foo bar
SignalR:调用myhub.Send jquery.signalR-2.2.1.min.js


解决方案

这是一个Firefox的bug。为我工作是在不同的时间致电通知。

  var randomTime = Math.floor((Math.random()* 20这是一个不完整的解决方案, )+ 1)* 50; 

setTimeout(function(){
newNotification = new Notification(Title,NotificationContent);
},randomTime);


By Web Notification I mean this (The Notification interface of the Notifications API is used to configure and display desktop notifications to the user).
I have Asp.Net MVC web app and I have a button in my page which supposed to push a notification to clients.
I also used signalr to push message and call notification function.

my layout.cshtml looks like this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
</head>
<body>
    <button id="btn" type="button">click</button>
    @RenderBody()
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.signalR-2.2.1.min.js"></script>
    <script src="~/signalr/hubs"></script>
    <script>
        jQuery(function ($) {
            var myHub = $.connection.chatHub;
            myHub.client.addNewMessageToPage = function (title, message) {
                var options = {
                    body: message,
                    tag: 'aaa'
                }

                // check permissions if already granted
                if (Notification.permission === "granted") {
                    var notification = new Notification(title, options);
                } else if (Notification.permission !== 'denied') {
                    // request permission
                    Notification.requestPermission(function (permission) {
                        // If the user accepts, let's create a notification
                        if (permission === "granted") {
                            var notification = new Notification(title, options);
                        }
                    });
                }

                console.log('the hub method called sucessfully');
            }
            $.connection.hub.logging = true;
            $.connection.hub.start().done(function () {
                $('#btn').on('click', function () {
                    myHub.server.send('foo', 'bar');
                });
            });
        });
    </script>
</body>
</html>

The problem is, the push notifications stops working/showing in firefox when I have multiple pages of my app open. (it works when single tab is open).
this bug only happens in firefox and works well in chrome and IE.

update 1: I think its not signalr problem since the hub method is invoked.
this line is called on all tabs: console.log('the hub method called sucessfully');
and signalr logging says that:

SignalR: Invoking myhub.Send jquery.signalR-2.2.1.min.js
SignalR: Triggering client hub event 'addNewMessageToPage' on hub 'MyHub'. jquery.signalR-2.2.1.min.js
foo bar
SignalR: Invoked myhub.Send jquery.signalR-2.2.1.min.js

解决方案

This is a Firefox bug.

The way worked for me was call the Notification in a different time. This is not a complete fix but is working well.

var randomTime = Math.floor((Math.random() * 20) + 1) * 50;

            setTimeout(function () {
                newNotification = new Notification(Title, NotificationContent);
            }, randomTime);

这篇关于Firefox桌面通知在多个选项卡打开时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆