reading-notes

Reading Notes for Codefellows

View the Project on GitHub kylecohen14/reading-notes

Reading 13 Local storage

“The past, present, & future of local storage for web applications” (http://diveinto.html5doctor.com/storage.html)

Everything quoted below comes from this article

THe past

HTML5 storage emerged

if (Modernizr.localstorage) {
  // window.localStorage is available!
} else {
  // no native support for HTML5 storage :(
  // maybe try dojox.storage or a third-party solution
} 

Use the above function to see if browser suppports HTML5 storage

function saveGameState() {
    if (!supportsLocalStorage()) { return false; }
    localStorage["halma.game.in.progress"] = gGameInProgress;
    for (var i = 0; i < kNumPieces; i++) {
	localStorage["halma.piece." + i + ".row"] = gPieces[i].row;
	localStorage["halma.piece." + i + ".column"] = gPieces[i].column;
    }
    localStorage["halma.selectedpiece"] = gSelectedPieceIndex;
    localStorage["halma.selectedpiecehasmoved"] = gSelectedPieceHasMoved;
    localStorage["halma.movecount"] = gMoveCount;
    return true;
}