I'd like to check weather my web application is running in background or foreground, You can check it very easily in JavaScript. hasFocus() is the function which tells that your window is active or not.
Here in below example I have create checkForeGroundBackGround() function and inside the body of it we check the window status.
We call back checkForeGroundBackGround() function periodically to check the status.
1
2
3
4
5
6
7
8
|
<script>
function checkForeGroundBackGroundStatus()
{
var isActive = window.document.hasFocus();
document.write(isActive);
}
setInterval(checkForeGroundBackGroundStatus, 2000);
</script>
|
window.document.hasFocus() returns the web app status true if app is in foreground and false if app is in background. ...