Created
October 19, 2023 22:07
-
-
Save HilquiasAbias/0f2b1a11d810b90ecc9c6c86dcafe524 to your computer and use it in GitHub Desktop.
Verificar tamanho do Local Storage do navegador
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="pt-br"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>LS size</title> | |
</head> | |
<body> | |
<div> | |
localStorage limit in your Browser is | |
<span id="size">...</span> KBs. | |
</div> | |
<script> | |
function generateRandomString(sizeInKB) { | |
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
const targetSizeInBytes = sizeInKB * 1024; | |
let result = ''; | |
while (result.length < targetSizeInBytes) { | |
const randomIndex = Math.floor(Math.random() * chars.length); | |
result += chars.charAt(randomIndex); | |
} | |
return result; | |
} | |
const randomString = generateRandomString(5119.9); | |
localStorage.setItem('a', randomString); | |
window.onload = function calculate() { | |
var el = document.getElementById('size'); | |
el.innerHTML = localStorage.getItem('a').length; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment