Firefox桌面通知在多个选项卡打开时不显示 [英] Firefox Desktop Notifications not showing when multiple tabs are open
问题描述
通过 Web通知
我的意思是
更新1 : 这是一个Firefox的bug。为我工作是在不同的时间致电通知。 By my 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). update 1:
I think its not signalr problem since the hub method is invoked.
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.
这篇关于Firefox桌面通知在多个选项卡打开时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
由于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
var randomTime = Math.floor((Math.random()* 20这是一个不完整的解决方案, )+ 1)* 50;
setTimeout(function(){
newNotification = new Notification(Title,NotificationContent);
},randomTime);
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.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>
this bug only happens in firefox and works well in chrome and IE.
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
var randomTime = Math.floor((Math.random() * 20) + 1) * 50;
setTimeout(function () {
newNotification = new Notification(Title, NotificationContent);
}, randomTime);