```js
var hidden = 'hidden';
var visibilitychange = 'visibilitychange';

[ "webkit", "moz", "ms"].forEach(function(prefix) {
  var prop = prefix + 'Hidden';
  if (typeof document[prop] !== 'undefined') {
    hidden = prop;
    visibilitychange = prefix + 'visibilitychange';
  }
});  
```