Skip to content

Instantly share code, notes, and snippets.

@dblotsky
Created January 15, 2018 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblotsky/ad43704d1be6df8307ecc89d900e7d3f to your computer and use it in GitHub Desktop.
Save dblotsky/ad43704d1be6df8307ecc89d900e7d3f to your computer and use it in GitHub Desktop.
Small reproduction of iOS reload bug.
<!DOCTYPE html>
<html>
<head>
<title>Reload Bug</title>
<style type="text/css">
p {
font-size: 3em;
}
</style>
<script type="text/javascript">
function getEventName() {
if (typeof document.hidden !== 'undefined') {
return 'visibilitychange';
} else if (typeof document.mozHidden !== 'undefined') {
return 'mozvisibilitychange';
} else if (typeof document.msHidden !== 'undefined') {
return 'msvisibilitychange';
} else if (typeof document.webkitHidden !== 'undefined') {
return 'webkitvisibilitychange';
}
}
function getPropertyName() {
if (typeof document.hidden !== 'undefined') {
return 'hidden';
} else if (typeof document.mozHidden !== 'undefined') {
return 'mozHidden';
} else if (typeof document.msHidden !== 'undefined') {
return 'msHidden';
} else if (typeof document.webkitHidden !== 'undefined') {
return 'webkitHidden';
}
}
function main() {
var hiddenProperty = getPropertyName();
var visibilityChangeEvent = getEventName();
var msg = (
'hiddenProperty: ' + hiddenProperty + '; ' +
'visibilityChangeEvent: ' + visibilityChangeEvent
);
console.log(msg);
document.addEventListener('visibilitychange', function() {
if (document['hidden']) {
console.log('lost focus');
} else {
console.log('reloading');
window.location.reload(true);
}
});
}
</script>
</head>
<body onload="main();">
<p>
This link should work: <a href="https://www.google.com">https://www.google.com</a>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment