App.js Add browser Back key support

Source: Internet
Author: User

App.js http://code.kik.com/app/2/index.html

(function (app,$) {var appload = app.load;var appback = app.back;function  Geturlpath (Args, options, callback,url) {var path = null;if (typeof args ===   "string") {Path = args;} Else if (typeof options ===  "string") {path = options;} Else if (typeof callback ===  "string") {Path = callback;} Else if (typeof url ===  "string") {Path = url;} Return path;} App.load = function (Pagename, args, options, callback,url) {var url =  Geturlpath (Args, options, callback,url);p ushstate (pageName); // //  whether a page with the same name has been loaded if   (App._pages.has (PageName))  {appload (pagename, args, options, callback); return;}   Parsing incoming htmlfunction parsepage (HTML) {return html; // todo we can  Enhance this }$.get (Url,function (res) {VAR PAGehtml = parsepage (res); $ ("Body"). Append (pagehtml); var page = $ (pagehtml). AppendTo (" Body "); App.add (pagename,$ ("[data-page= '" +pagename+ "]") [0]); AppLoad (Pagename, args, options, callback) ;});}; var internalback = false; App.back = function (pagename, callback) {Internalback = true;appback (pageName,  callback); History.back ();}; Function pushstate (pageName) {window.history.pushState ({name:pagename}, "", "#/" +pagename);} Window.onpopstate = function (event) {Var state = event.state;console.log (state); Internalback) {appback ();} Internalback = false;}}) (Window. app,$);


App.js Add browser Back key support

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.