- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>title 消息提示 </title>
- </head>
- <body>
- <button id='start'> 开始 </button>
- <button id='end'> 停止 </button>
- <script>
- var timer;
- var flag = true;
- var loop = () => {
- if (flag) {
- window.document.title = '[您有新消息]';
- } else {
- window.document.title = '\u200E';
- }
- flag = !flag;
- timer = setTimeout(loop, 500);
- }
- timer = setTimeout(loop, 500);
- document.getElementById('start').addEventListener('click', function() {
- clearTimeout(timer);
- timer = setTimeout(loop, 500);
- }, false);
- document.getElementById('end').addEventListener('click', function() {
- clearTimeout(timer);
- window.document.title = 'title 消息提示';
- }, false);
- </script>
- </body>
- </html>
来源: http://www.qdfuns.com/article/45591/e178996fc1cbc2676754690c6e153a83.html