A page is loaded with Ajax data, and is a scrolling effect, when scrolling through a few screens, into the new link page B, and then return to a, the data of a page needs to be reloaded, from the beginning, the experience is very bad.
Solution: (1) hash;2) HTML5 's history characteristics, 3) Localstorage/cookie, and so on, Localstorage is the simplest, do not need to introduce other things, simple transformation can be achieved.
Reset page Environment function Resetstatus () {var oldstatus = Window.localStorage.getItem ("Goodstatus"); If the data is not stored locally, load the if (Oldstatus = = null) {LOADPDT () directly from the beginning; Return }//extract locally stored data var Oldjson = Json.parse (oldstatus); page = Oldjson.page; if (OldJson.kw.length > 0) {$ ("#search_input"). Val (oldjson.kw); $ ("#search_text"). Hide (); $ ("#search_cancel"). Show (); } = Oldjson.order; Ctgid = Oldjson.ctgid; -----------//something Todo//-----------//directly display the stored HTML to page $ ("#goodsList"). HTML (Window.lo Calstorage.getitem ("Goodlist")); Clear local data to prevent active refresh of Window.localStorage.removeItem ("Goodstatus"); Window.localStorage.removeItem ("Goodlist"); }//instead of a link before the direct jump way, the purpose is to store the data function Openpdtdetail (ID) {//Storage data Window.localStorage.setItem ("Goo Dstatus ", Json.stringify ({page:page, kw: $.trim($ ("#search_input"). Val ()), Order:orderby, ctgid:ctgid}); Window.localStorage.setItem ("Goodlist", $ ("#goodsList"). html ()); Window.location.href = "/mobile/goods/detail/" + ID + "[email protected][" Sid "]"; }
And found that there is a benefit, the HTML content will be displayed to the page, will automatically return to the original location, no need to re-locate.
HTML5 Localstorage solves the pit of Ajax fallback