Is it possible to detect when the user switches tabs?

In particular, I am interested in knowing whether it is possible to capture a user by clicking on another browser tab. I suppose that 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.

+3
source share
1 answer

IE

If you write your own code (i.e. a browser plug-in), you can use DWebBrowserEvents2 :: WindowStateChanged .

Here is a sample code to implement IDispatch::Invoke():

    // 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 , , , .

Firefox

Firefox XUL, TabAttrModified selected. . MDC .

+4

Source: https://habr.com/ru/post/1785961/


All Articles