美文网首页
实用小功能,让你的网页标签页头部有新消息提醒

实用小功能,让你的网页标签页头部有新消息提醒

作者: mtian999 | 来源:发表于2019-08-02 15:41 被阅读0次

html 代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id='shiftBtn' type="button" name="button">开关</button>
    <script src='http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js'></script>
    <script type="text/javascript">
    $(function(){
        var timeout=true;
        var count=0;
        var titleOrigin='';
        var running=0;

        $('#shiftBtn').on('click',function(){
            if(count==0){
                titleOrigin=$('title',window.top.document).html();
                $('title',window.top.document).html('【有新提醒】'+titleOrigin);
                count++;
            }
            if(timeout){
                    timeout=false;
            }else{
                    timeout=true;
            }
                        if(running)return;
            time();
        })
        function time()
        {
          running=1;
          if(timeout) {
                $('title',window.top.document).html(titleOrigin);
                count=0;
                running=0;
                return;
            }
          Method();
          setTimeout(time,500); //time是指本身,延时递归调用自己,500为间隔调用时间,单位毫秒
        }
        function Method(){
            var titlePre=$('title',window.top.document).html().match(/\【[\s\S]*\】/)[0];
            var titleafter=$('title',window.top.document).html().replace(titlePre,'');

            if(titlePre=='【有新提醒】'){
                $('title',window.top.document).html('【&emsp;&emsp;&emsp;&emsp;】'+titleafter)
            }else{
                $('title',window.top.document).html('【有新提醒】'+titleafter)
            }
        }

    })
    </script>
</body>

</html>

相关文章

网友评论

      本文标题:实用小功能,让你的网页标签页头部有新消息提醒

      本文链接:https://www.haomeiwen.com/subject/krvldctx.html