码迷,mamicode.com
首页 > 其他好文 > 详细

jQurey浏览器页卡切换 用于实时接口的长轮询

时间:2014-09-19 20:52:16      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   java   ar   div   sp   

加页卡切换,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <script type="text/javascript" src="http://mat1.gtimg.com/www/js/jquery/jquery-1.11.1.min.js"></script>
    <script>

/***
   切换浏览器tab,判断当前tab是否活跃
***/

    (function(g, h, $, b) {
        var e, i, f = onfocusin in h && hasFocus in h ? focusin focusout : focus blur,
            d = [‘‘, moz, ms, o, webkit],
            c = $.support,
            a = $.event;
        while ((i = e = d.pop()) != b) {
            i = (e ? e + H : h) + idden;
            if (c.pageVisibility = typeof h[i] == boolean) {
                f = e + visibilitychange;
                break
            }
        }
        $(/blur$/.test(f) ? g : h).bind(f,
            function(m) {
                var l = m.type,
                    j = m.originalEvent,

                    k = j.toElement;

                if (!/^focus./.test(l) || (k == b && j.fromElement == b && j.relatedTarget == b)) {
                    a.trigger((i && h[i] || /^(?:blur|focusout)$/.test(l) ? hide : show) + .visibility)
                }
            })
    }(this, document, jQuery));

    var o={}
    o.$tabFlag = true;
     /**  切换页卡 **/  

    var changeTab=function() {

        //var _this = this;
        //var o = this.options;
        console.log(333)
        $(document).bind({
            show.visibility: function() { // 当前活跃
                o.$tabFlag = true;

                console.log(222)
            },

            hide.visibility: function() { // 失去当前状态
                o.$tabFlag = false;
                console.log(11111)
            }
        });
    }
    
    changeTab();

    </script>


</head>
<body>
    
</body>
</html>
  

 

jQurey浏览器页卡切换 用于实时接口的长轮询

标签:style   blog   http   color   io   java   ar   div   sp   

原文地址:http://www.cnblogs.com/cssfirefly/p/3982100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!