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]
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.
– Papa Charlie
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)
– RFL
how would I do that ? would have another suggestion to get the user’s attention ?
– Dnight
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.– user622