不断检查窗口的焦点 [英] Checking the window's focus constantly

查看:49
本文介绍了不断检查窗口的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在这里我需要经常检查windows焦点,我想检查用户是否存在于我的网站上,否则他会将焦点集中在其他地方。这必须在他们调用事件后的某个特定时间完成。


Here i need to check the windows focus constanly, i want to check whether the user is existing on my site or else he focus some where else. This has to be done for some particular time, after they called an event.

我使用过self.focus()和window.focus()没有用,它总是返回本机代码。我想要检查我的窗口(网站)的重点是什么?

I have used self.focus() and window.focus() there is not use, its always return the "native code". What i suppose to do for checking my window (site) is focused or not

谢谢,
Praveen j

推荐答案

你需要同时捕获焦点模糊事件并更新变量因此,从(希望)窗口在打开时具有焦点的事实开始。

You need to trap both the focus and blur events and update a variable accordingly, starting with the fact that (hopefully) the window has the focus when it is opened.

var hasFocus = true;
window.onfocus = function() {
    hasFocus = true;
};
window.onblur = function() {
    hasFocus = false;
};

这篇关于不断检查窗口的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆