浏览器窗口被激活

来源:互联网 发布:asp工资管理系统源码 编辑:程序博客网 时间:2024/05/21 18:47
        window.onload = function () {
            var CurrentActive;
            window.onfocus = function () {
                CurrentActive = true;
                document.body.innerHTML += "当前窗口被激活";
            }
            window.onblur = function () {
                CurrentActive = false;
                document.body.innerHTML += "当前窗口没有激活";
            }
        }
        /*经测试fx,ie(7-10)当页面第一次打开页面时,执行一次onfocus。而chrome未执行。
        之后每次切换页面,fx,ie(7-10) 分别执行获取焦点和移出焦点。而chrome这两个事件分别多执行一次。
        其它只有当鼠标进入浏览器地址输入模式才会触发window获取或推动焦点动作,而chrome仍为执行两次。
        */
 
        /*
        //jquery 下如何获取当前窗口被激活  
        $(window).focus(function () {
            //处于激活状态
        });
 
        $(window).blur(function () {
            //处于未激活状态
        });
        */
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }

<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>