I have a news site that is powered by C# ASP.Net MVC 5.0 and I want to push notification to clients browser when an admin add/edit or delete a news.
so I added a signalr script to my template which is used in all pages.
_Layout.cshtml
var notificationsHub = $.connection.notificationHub;
$.connection.hub.start();
jQuery(function($) {
notificationsHub.client.Toast = function (title, body) {
var options = {
body: body,
};
var notification = new Notification(title, options);
};
});
and added this code to the page that redirects after news add/edit/delete is done
<script>
$.connection.hub.start().done(function() {
notificationsHub.server.toast('@NotificationHub.Type.ToString()', '@Html.Raw(NotificationHub.Title)', '@Html.Raw(NotificationHub.Body)');
});
</script>
when I add/edit/delete a news it works fine but the problem is it pushes notification to all opened tabs in my site. is there a trick to avoid this happening and show only one browser notification per site?