Created
January 15, 2018 06:03
-
-
Save dblotsky/ad43704d1be6df8307ecc89d900e7d3f to your computer and use it in GitHub Desktop.
Small reproduction of iOS reload bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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