Use JS to flash the browser title

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.