Skip to content

Instantly share code, notes, and snippets.

@toothfairy
Created September 16, 2014 09:01
Show Gist options
  • Save toothfairy/bd278a698d5cd36f515b to your computer and use it in GitHub Desktop.
Save toothfairy/bd278a698d5cd36f515b to your computer and use it in GitHub Desktop.
Crossbrowser howler mute on tab live
hidden = undefined
visibilityChange = undefined
if typeof document.hidden isnt "undefined" # Opera 12.10 and Firefox 18 and later support
hidden = "hidden"
visibilityChange = "visibilitychange"
else if typeof document.mozHidden isnt "undefined"
hidden = "mozHidden"
visibilityChange = "mozvisibilitychange"
else if typeof document.msHidden isnt "undefined"
hidden = "msHidden"
visibilityChange = "msvisibilitychange"
else if typeof document.webkitHidden isnt "undefined"
hidden = "webkitHidden"
visibilityChange = "webkitvisibilitychange"
handleVisibilityChange = ->
if document[hidden]
Howler.mute()
else
Howler.unmute()
return
document.addEventListener visibilityChange, handleVisibilityChange, false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment