<script type="text/javascript">
if(localStorage) { // Check if the localStorage object exists
localStorage.clear() //clears the localstorage
} else {
alert("Sorry, no local storage."); //an alert if localstorage is non-existing}
</script>
要确认localStorage是否为空,请使用以下代码:
<script type="text/javascript">
// Check if the localStorage object existsif(localStorage) {
alert("Am still here, " + localStorage.getItem("your object name")); //put the object name} else {alert("Sorry, i've been deleted ."); //an alert}
</script>