Newer browsers (IE10 and up) have support for the Page Visibility API
The Page Visibility API lets you know when a webpage is visible or in
focus. With tabbed browsing, there is a reasonable chance that any
given webpage is in the background and thus not visible to the user.
When the user minimizes the webpage or moves to another tab, the API
sends a visibilitychange event regarding the visibility of the page.
You can detect the event and perform some actions or behave
differently. For example, if your web app is playing a video, it would
pause the moment the user looks at another browser, and plays again
when the user returns to the tab. The user does not lose their place
in the video and can continue watching.
Used something like this
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
document.addEventListener(visibilityChange, handleVisibilityChange, false);
function handleVisibilityChange() {
$("video").prop('muted', document[hidden]);
}
DEMONSTRATION