Code function $(id) { return document.getElementById(id); } function clearTextBoxes() { $('value').value = ""; $('key').value = ""; } function saveSession() { if (!sessionStorage) { alert("Your browser does not support session web storage"); } else { var key = $('key').value; var value = $('value').value; if (key && value) sessionStorage.setItem(key, value); else alert("Either the key or value (or both) were missing."); window.location.reload(); } clearTextBoxes(); return false; } function saveLocal() { if (!localStorage) { alert("Your browser does not support local web storage"); } else { var key = $('key').value; var value = $('value').value; if (key && value) localStorage.setItem(key, value); else alert("Either the key or value (or both) were missing."); window.location.reload(); } clearTextBoxes(); return false; } function clearStorage() { if (localStorage) localStorage.clear(); if (sessionStorage) sessionStorage.clear(); window.location.reload(); return false; } window.onload = function() { clearTextBoxes(); $('btnSaveLocal').onclick = saveLocal; $('btnSaveSession').onclick = saveSession; $('btnClear').onclick = clearStorage; var msg = ""; var i = 0; if (sessionStorage) { var ssLength = sessionStorage.length; if (ssLength > 0) { msg += 'Session storage'; msg += ''; for (i=0; i' + ssKey + ' = ' + sessionStorage.getItem(ssKey) + ''; } msg += ''; } } if (localStorage) { var lsLength = localStorage.length; if (lsLength > 0) { msg += 'Local storage'; msg += ''; for (i=0; i' + lsKey + ' = ' + localStorage.getItem(lsKey) + ''; } msg += ''; } } if (!localStorage && !sessionStorage) $('results').innerHTML = 'Web storage not available.'; else if (msg == "") $('results').innerHTML = 'No data found in web storage.'; else $('results').innerHTML = msg; };