Testing LocalStorage Across Browsers

Using some basic example code to assess how local storage behaves when browsers load in restricted contexts (incognito mode, cookies enabled/disabled, etc.)

by Andrew Holloway

HTML

<h1 id="test">
Start
</h1>

JavaScript

(function() {
	document.addEventListener('DOMContentLoaded', function() {
  	// Set some content to the local store, then read it in, and put it into the Header
    var ls = window.localStorage;
    ls.setItem('test', 'After');
    
    var h1 = document.querySelector('#test');
    
    h1.innerHTML = ls.getItem('test');
  	});
})();