The setTimeout method is used to set a timer, switch the message prompts, and reach the title to the Message prompts.
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> JS effect-flashing browser title bar </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Script type = "text/javascript">
// Use the message object to encapsulate the message
Var message = {
Time: 0,
Title: document. title,
Timer: null,
// Display the new message prompt
Show: function (){
Var title = message. title. replace ("[]", ""). replace ("[NEW message ]","");
// Timer, set the message switching frequency to flash.
Message. timer = setTimeout (function (){
Message. time ++;
Message. show ();
If (message. time % 2 = 0 ){
Document. title = "[new message]" + title
}
Else {
Document. title = "[]" + title
};
},600 );
Return [message. timer, message. title];
},
// Cancel the new message prompt
Clear: function (){
ClearTimeout (message. timer );
Document. title = message. title;
}
};
Message. show ();
// Bind the click event when loading the page, and click the cancel flashing prompt
Function bind (){
Document. onclick = function (){
Message. clear ();
};
}
</Script>
</Head>
<Body>
Click the page to cancel the message flashing prompt.
</Body>
</Html>