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.
var isActive = window.document.hasFocus();
window.document.hasFocus() returns the web app status true if app is in foreground and false if app is in background. ...