Created
February 11, 2025 11:06
-
-
Save franky47/5a8e9aab42536224bb93f840b8f7f57f to your computer and use it in GitHub Desktop.
Vanilla HTML URL state
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Vanilla</title> | |
</head> | |
<body> | |
<label style="display: flex; gap: 0.5rem; align-items: center"> | |
<input type="range" id="slider" /> | |
<span id="value"></span> | |
</label> | |
<script type="module"> | |
addEventListener('load', () => { | |
const slider = document.getElementById('slider') | |
const label = document.getElementById('value') | |
const searchParams = new URLSearchParams(location.search) | |
slider.setAttribute('value', searchParams.get('value') || '50') | |
label.textContent = slider.value | |
slider.addEventListener('input', event => { | |
label.textContent = event.target.value | |
history.replaceState(null, '', `?value=${event.target.value}`) | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Showcases how updating the URL (using the History API) at direct event rates can cause failures due to rate-limiting.