Created
September 14, 2021 06:31
-
-
Save jaikt/8b95176527dea7e4d927a0a494d45eba to your computer and use it in GitHub Desktop.
How To Stop Auto Refresh Page Using JavaScript
This file contains hidden or 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
<script> | |
var state = history.state || {}; | |
var reloadCount = state.reloadCount || 0; | |
if (performance.navigation.type === 1) { // Reload | |
state.reloadCount = ++reloadCount; | |
history.replaceState(state, null, document.URL); | |
} else if (reloadCount) { | |
delete state.reloadCount; | |
reloadCount = 0; | |
history.replaceState(state, null, document.URL); | |
} | |
if (reloadCount >= 5) { | |
window.location.href = ""; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment