How to focus on a specific browser tab from a php check

1

I would like that from a defined time if the user has selected another tab, or is seeing something else in the browser (Email), the system page is selected as if it were changed from tab, while the user has a time return limit, so I would force the user to return to the system and perform its mandatory activities

    
asked by anonymous 09.04.2015 / 16:22

2 answers

1

No it is possible to change tabs, due to browser security precautions.

But in any case if it helps you, there is a way to detect if the system page is or is not currently active, via Visibility API .

Add the code below:

<script>
var vis = (function(){
    var stateKey, eventKey, keys = {
        hidden: "visibilitychange",
        webkitHidden: "webkitvisibilitychange",
        mozHidden: "mozvisibilitychange",
        msHidden: "msvisibilitychange"
    };
    for (stateKey in keys) {
        if (stateKey in document) {
            eventKey = keys[stateKey];
            break;
        }
    }
    return function(c) {
        if (c) document.addEventListener(eventKey, c);
        return !document[stateKey];
    }
})();
</script>

With this, you can retrieve the status of the page as follows:

<script>
var visible = vis();
</script>

And your variable visible will now contain the value 'Visible' or 'Not visible' according to the status of the active page at the moment.

If you want to see how it works you have a demo page that changes the page title when it is focused / blurred.

I hope I have helped.

[Remembering that the above code refers to javascript and not php as it speaks in the question]

    
11.06.2015 / 14:21
0

If you open a page through yours, such as via javascript with window.open, you can name it, and give focus by activating it by name. If it is a page that you know the name can also make the window.elemento.focus () by calling the window q you want.

    
10.04.2015 / 15:46