H5 application return button JS code design, design ideas imitate stack

Source: Internet
Author: User
Tags sessionstorage

History.back ();

This code has a natural flaw, used to know, in the application of H5, especially the imitation of mobile phone applications, this is not enough.

Close-up a section of JS to achieve similar functions, such as repeated and do not like please light spray.


Not much to say, on the code:

/** * Created by [email protected] on 2015/5/28.        */var historyutils = {add:function (URL) {var historyarray = historyutils.getlocal ();        if (!historyarray) {historyarray = [];        } var currentpage = Historyarray.pop (); if (currentpage && currentpage = = URL) {//do nothing} else if (currentpage) {Histor Yarray.push (currentpage);        In history there is no incoming URL now, in Add back} historyarray.push (URL);    Historyutils.savelocal (Historyarray);        }, Back:function () {var historyarray = historyutils.getlocal ();        var currentpage = Historyarray.pop ();//Remove current page, pop take last, similar to stack var history = Historyarray.pop ();        if (!history) {//No history page Historyutils.add (currentpage);//Add the current page back to the array return;        } historyutils.savelocal (Historyarray);    Window.location.href = history; }, Getlocal:function () {var result = Window.sessionStorage.getItem (hiStoryutils.key);        if (!result) {return null;    } return Json.parse (result);    }, Savelocal:function (data) {Window.sessionStorage.setItem (Historyutils.key, json.stringify (data));    }, Init:function () {historyutils.savelocal ([]); }, Key: "_history_"}historyutils.add (window.location.href);


Call where you need to implement back.

Historyutils.back ();



H5 application return button JS code design, design ideas imitate stack

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.