Javascript-文档/窗口有焦点吗?

And*_*Hin 1 javascript

可能重复:
如何找出哪个Javascript元素有焦点?

是否可以在Javascript中检查当前窗口是否具有焦点?

Koo*_*Inc 8

不,不是真的.可能是您可以将处理程序分配给窗口的焦点/模糊事件,将布尔值设置为true或false,并使用它来确定它是否具有焦点.

这条线上的东西:

window.hasfocus = false;

window.onfocus = function(){
   this.hasfocus = true;
}

window.onblur = function(){
   this.hasfocus = false;
}
Run Code Online (Sandbox Code Playgroud)