문제

I want to show the users how much memory they can use and how much memory they used so far.

For example, something like this:

도움이 되었습니까?

해결책

Yes, it's possible. Its a bit tricky to get a % though:

$('#usageDiv').value(((JSON.stringify(localStorage).length * 2)/1024).toFixed(2)+" KB");

The *2 is because characters in Javascript are UTF16 (2 bytes per char). To get the maximum space, you can basically only "test it". Take a look at how they do it

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top