var CurrentActive; window.onfocus = function() { CurrentActive = true; document.body.innerHTML +="当前窗口被激活"; } window.onblur = function() { CurrentActive = false; document.body.innerHTML += "当前窗口没有激活"; }