Last active
December 29, 2015 22:09
-
-
Save cou929/7734384 to your computer and use it in GitHub Desktop.
localStorage privacy setting sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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