基础 - 访问历史
function funQianJin() { window.history.forward(); } function funHouTui() { window.history.back(); } function funShuaXin() { window.history.go(); }
H5
/*留下历史记录*/ if (window.history && window.history.pushState) { window.history.pushState("event.state","预留,暂时无用","?mark="+"地址栏显示内容"); } /*点击前进或后退自动调用*/ window.addEventListener("popstate",function(event) { console.log(event.state); })
/** * 解析地址栏 * encodeURI() 将普通字符串百分化 * decodeURI() 将百分字符串普通化 **/ var sFlxAdd = window.location.search; var sMarkEx = sFlxAdd.split("mark=")[1].split("&")[0]; var sMark = decodeURI(sMarkEx); console.log(sMark);