原理就是利用localStorage存储是否是第一次登录的标识,用此标识来判断要跳到哪个页面
1,建立一个引导页guide.html,建立一个判断页面judgePage.html
在判断页面judgePage.html 判断该跳到哪个页面,代码如下:
var userid = localStorage.getItem("userId");
mui.init();
mui.ready(function() {
/**
* 获取本地存储中launchFlag的值
* http://www.html5plus.org/doc/zh_cn/storage.html#plus.storage.getItem
* 若存在,说明不是首次启动,直接进入首页;
* 若不存在,说明是首次启动,进入引导页;
*/
var launchFlag = localStorage.getItem("launchFlage");
if(launchFlag) {
if (userid) {// 若存在userid则进入首页,否则进入登录页面
window.location.href = "index.html";
} else{
window.location.href = "sys/login.html";
}
} else {// 若不存在launchFlag则进入guide.html页面
// 参数id与url页面前缀相同
mui.openWindow({
url: "guide.html",
id: "guide"
});
}
});
2,在进入guide.html页面后,将launchFlage设置为true
localStorage.setItem("launchFlage","true");