TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

HTML5: Local Storage oddities & tips

4 pointsby jdavidalmost 15 years ago
HIJACKING localStorage<p>in chrome you can hijack basic functions in localStorage and then when they are called later, they call the replaced function.<p><pre><code> localStorage.getItem = function(val){ console.log( val ); } //function (val){ console.log( val ); } localStorage.getItem( "truck" ); //truck //undefined localStorage.getItem2 = function(val){ console.log( val ); } //function (val){ console.log( val ); } localStorage.getItem2( "truck" ); //TypeError: Property 'getItem2' of object #&#60;a Storage&#62; is not a function </code></pre> localStorage keys can be any unicode character.<p><pre><code> for( var i = 0; i &#60; 32000; i ++ ){ localStorage[ String.fromCharCode(i) + "_test" ] = String.fromCharCode(i) + "_test"; } </code></pre> localStorage does not have a prototype<p>but, Storage.prototype is the prototype for localStorage, so you can add methods there.<p>localStorage NAMESPACING<p>i am wondering how one should namespace content on the same page large data sets seem dangerous.<p>localStorage private keys if a key starts with a character that is not property safe, it must be accessed via the array notation localStorage[key] rather than dot notation. using one of these chars in front of all of your keys could prevent you from overwriting key functions.<p>what are other localStorage hacks that you guys have found?

no comments

no comments