物理返回页面重新执行js
var isPageHide = false;
window.addEventListener('pageshow', function() {
if(isPageHide) {
window.location.reload();
}
});
window.addEventListener('pagehide', function() {
isPageHide = true;
});
存储
var arr = localStorage.getItem("reading");
if(arr){
arr=arr.split(",");
}else{
arr=[];
}
var storage=window.localStorage;
arr.push($this.attr("data-s"));
if (storage) {
localStorage.setItem("reading", arr);
}
数组去重
function arrsort(ar) {
var ret = [];
ar.forEach(function(e, i, ar) {
if (ar.indexOf(e) === i) {//indexOf记录内容第一次出现的位置
ret.push(e);
}
});
return ret;
}
读取
var strStoreDate = localStorage.getItem("reading");
if(strStoreDate) {
var read=strStoreDate.split(",");
read=arrsort(read);
$.each(read,function(index,value){
$("."+value).find("i").remove();
})
}