App.js添加浏览器返回键支持
app.jshttp://code.kik.com/app/2/index.html
(function(App,$){varappLoad=App.load;varappBack=App.back;App.load=function(pageInfo,args,options,callback){varpageName=null;varurl=null;if(typeofpageInfo==="string"){pageName=pageInfo;}elseif(typeofpageInfo==="object"){pageName=pageInfo.name;url=pageInfo.url;}pushState(pageName);////是否有同名的页面已经加载if(App._Pages.has(pageName)){appLoad(pageName,args,options,callback);return;}//解析传入的htmlfunctionparsePage(html){returnhtml;//TODOwecanenhancethis}$.get(url,function(res){varpageHtml=parsePage(res);varpage=$(pageHtml).appendTo("body");App.add(pageName,page[0]);appLoad(pageName,args,options,callback);});};varinternalBack=false;App.back=function(pageName,callback){internalBack=true;appBack(pageName,callback);history.back();};functionpushState(pageName){window.history.pushState({name:pageName},"","#/"+pageName);}window.onpopstate=function(event){varstate=event.state;if(!internalBack){appBack();}internalBack=false;}})(window.App,$);
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。