Skip to content

Instantly share code, notes, and snippets.

@cou929
Last active December 29, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cou929/7734384 to your computer and use it in GitHub Desktop.
Save cou929/7734384 to your computer and use it in GitHub Desktop.
localStorage privacy setting sample
<!DOCTYPE html>
<html>
<head>
<title>localStorage and privacy setting sample</title>
</head>
<body>
<div id="result"></div>
<script>
(function() {
var key = 'localstorage_test_item',
result_field = document.getElementById('result');
if (!window.localStorage) {
result_field.innerHTML = 'localStorage is not supported';
return;
}
var got_first = window.localStorage.getItem(key);
if (!got_first) {
value = [(new Date()).toString(), Math.floor(Math.random() * 10e12)].join('\t');
window.localStorage.setItem(key, value);
}
var got_second = window.localStorage.getItem(key);
result_field.innerHTML = [
'first get: ' + (got_first || ''),
'second get: ' + (got_second || ''),
].join('<br/>')
})();
</script>
<iframe src="https://dl.dropboxusercontent.com/u/151946/localstoragesample/sample_iframe.html"></iframe>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>in iframe - localStorage and privacy setting sample</title>
</head>
<body>
<div id="result"></div>
<script>
(function() {
var key = 'localstorage_test_item',
result_field = document.getElementById('result');
if (!window.localStorage) {
result_field.innerHTML = 'localStorage is not supported';
return;
}
var got_first = window.localStorage.getItem(key);
if (!got_first) {
value = [(new Date()).toString(), Math.floor(Math.random() * 10e12)].join('\t');
window.localStorage.setItem(key, value);
}
var got_second = window.localStorage.getItem(key);
result_field.innerHTML = [
'first get: ' + (got_first || ''),
'second get: ' + (got_second || ''),
].join('<br/>')
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment