Local Storage

Local Storage ===J.O.B===/HTML 2012. 3. 22. 16:24
 http://dev.w3.org/html5/webstorage/ 
 http://en.wikipedia.org/wiki/Web_Storage 

================================================================================================================================ 

================================================================================================================================ 

localStorage.setItem("name", "Hello World!"); //saves to the database, key/value
document.write(localStorage.getItem("name")); //Hello World!
localStorage.removeItem("name"); //deletes the matching item from the database

================================================================================================================================ 

if (typeof(localStorage) == 'undefined' ) {
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
} else {
try {
localStorage.setItem("name", "Hello World!"); //saves to the database, "key", "value"
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded!'); //data wasn't successfully saved due to quota exceed so throw an error
}
}
 
document.write(localStorage.getItem("name")); //Hello World!
localStorage.removeItem("name"); //deletes the matching item from the database
}

==================================================================================================================

var car = {};
car.wheels = 4;
car.doors = 2;
car.sound = 'vroom';
car.name = 'Lightning McQueen';
console.log( car );
localStorage.setItem( 'car', JSON.stringify(car) ); 
console.log( JSON.parse( localStorage.getItem( 'car' ) ) ); 

'===J.O.B=== > HTML' 카테고리의 다른 글

Eclipse IDE 에서 Zen-Coding 소개  (1) 2010.05.31
HTML5 강좌 관련 사이트  (0) 2010.05.20
HTML5 데모와 예제 목록을 공유  (0) 2010.05.17
Posted by 샤가No01
하단 사이드바 열기

BLOG main image