jquery 通知页面变化

时间:2023-12-21 10:04:08
var PageTitleNotification = {
Vars: {
OriginalTitle: document.title,
Interval: null,
IsNotificationEnabled: false
},
On: function (notification, intervalSpeed) {
var _this = this;
_this.Vars.Interval = setInterval(function () {
document.title = (_this.Vars.OriginalTitle == document.title)
? notification
: _this.Vars.OriginalTitle;
}, (intervalSpeed) ? intervalSpeed : 1000);
},
Off: function () {
clearInterval(this.Vars.Interval);
document.title = this.Vars.OriginalTitle;
}
}
$(window).focus(function () {
PageTitleNotification.IsNotificationEnabled = false;
PageTitleNotification.Off();
}); $(window).blur(function () {
PageTitleNotification.IsNotificationEnabled = true;
});
if (PageTitleNotification.IsNotificationEnabled)
PageTitleNotification.On("New Chat Message!");