I attempted to post the following code snippet using HTML5 local storage, but I receive:
Submit { "message": "Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.", "filename": "https://stacksnippets.net/js", "lineno": 27, "colno": 23 }
Here is the jsfiddle that works: http://jsfiddle.net/jvso1Lcc/22/
Below is the snippet:
function reload() {
localStorage.setItem('selectedVal',$('#mySelect').val());
location.reload(true);
}
$( document ).ready(function() {
var selectedVal = localStorage.getItem('selectedVal');
if (selectedVal){
$('#mySelect').val(selectedVal)
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id='mySelect'>
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
<button onclick="reload()">Submit</button>
<iframe>
on JSFiddle has theallow-same-origin
flag in thesandbox
attribute.