是否有可能在用户切换标签检测? [英] Is it possible to detect when a user switches tabs?
问题描述
在特别的,我想知道是否可以捕捉用户的点击不同的浏览器选项卡。我想在技术上我能得到的窗口对象的模糊和焦点,但如果有更多的东西紧密联系在一起的浏览器(IE,FF,铬等),这将是更好的。
In particular, I am interested to know if it is possible to capture a user's click to a different browser tab. I guess technically I could get the blur and focus of the window object but if there was something more closely tied to the browser (IE, FF, Chrome, etc.) that would be even better.
推荐答案
IE
如果你正在写原生code(即浏览器插件),可以使用的 DWebBrowserEvents2 :: WindowStateChanged 。
If you are writing native code (i.e. a browser plug-in) you can use DWebBrowserEvents2::WindowStateChanged.
下面是一些示例code,你的的IDispatch ::调用()
实施
Here is some sample code, for your IDispatch::Invoke()
implementation:
// DWebBrowserEvents2
case DISPID_WINDOWSTATECHANGED: {
if (pDispParams) {
DWORD dwMask = pDispParams->rgvarg[0].lVal;
DWORD dwFlags = pDispParams->rgvarg[1].lVal;
// We only care about WINDOWSTATE_USERVISIBLE.
if (dwMask & OLECMDIDF_WINDOWSTATE_USERVISIBLE)
{
bool visible = !!(dwFlags & OLECMDIDF_WINDOWSTATE_USERVISIBLE));
// ... your code here ...
}
}
break;
}
有是发送到网页的Javascript没有显式事件,但模糊事件可能做你的愿望。
There is no explicit event sent to the Javascript of the page, but the blur event may do what you desire.
火狐
在Firefox中,你可以通过添加一个事件侦听器 TabAttrModified
和检验检测您的XUL标签更改选
属性。请参阅<一个href=\"https://developer.mozilla.org/en/$c$c_snippets/Tabbed_browser#Notification_when_a_tab%27s_attributes_change\"相对=nofollow> MDC文档与分页浏览器的处理。
In Firefox you can detect tab changes in your XUL by adding an event listener for TabAttrModified
and inspecting the selected
attribute. See the MDC documentation for the dealing with the Tabbed Browser.
这篇关于是否有可能在用户切换标签检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!