how to recognize foregound or background state of application
Using visibilitychange event, we can recognize foreground or background state of application.
document.addEventListener("visibilitychange", pageVisibilityHandler, false);
function pageVisibilityHandler()
{
if (!(document.hidden))
{
console.log("visible");
}
else
{
console.log("hidden");
}
}