This new message prompt effect is used in the company’s projects, and is mainly used to remind users that there are new messages. The specific implementation code is as follows:
var newMessageRemind = {
_step: 0,
_title: document.title,
_timer: null,
//Show new message prompt
show: function() {
var temps = newMessageRemind._title.replace("【 】", "").replace("[New Message]", "");
newMessageRemind._timer = setTimeout(function() {
newMessageRemind.show();
//Write Cookie operation here
newMessageRemind._step ;
if (newMessageRemind._step == 3) {
newMessageRemind._step = 1
};
if (new MessageRemind._step == 1) {
document.title = "【 】" temps
},
800); ;
document.title = newMessageRemind._title;
//Write Cookie operation here
}
};
Call to display new message reminder: newMessageRemind.show();
Call to cancel new message reminder: newMessageRemind.clear();
Another: This simple code will cause such a problem:
That is, when you open many pages of a site, if there is new news, all the pages will keep flashing. When you Other pages will still prompt after viewing the message.
Our company solves the problem by using cookies. When viewing new messages, all pages with flashing titles will cancel the prompt.