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

Asked

Viewed 932 times

1

I would like that from a set 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 tab, and the user has a return time limit, so I would force the user to return to the system and perform its mandatory activities

  • 1

    This is a very big intrusion - it’s like taking out the book I’m reading... From what I know it’s not allowed to change the tab the user is in. Use a sound system or Chrome notifications.

  • Create a timer and run an audio after the set time, as soon as the audio starts the audio icon will appear in the tab. (Chrome)

  • how would I do that ? would have another suggestion to get the user’s attention ?

  • Sorry, but what does this have to do with PHP? If you want to draw the user’s attention to another tab, just use one alert javascript. Or you can animate the title (document.title) or use notifications, as Pope Charlie said.

2 answers

1

Not it is possible to make tab change due to browser security precautions.

But in any case if it helps you, there is how to detect whether or not the system page is active at the moment, through the 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 recover the status of the page as follows:

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

And its variable visible will contain the value 'Visible' or 'Not visible' according to the current active page status.

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

I hope I’ve helped.

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

0

If you open a page through yours, for example via javascript with window.open, you can name it, and focus by calling it by name. If it’s a q page you know the name can also do the window.elemento.Focus() calling the window q you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.