what will persist when returning via back button?

后端 未结 4 986
盖世英雄少女心
盖世英雄少女心 2021-01-02 00:49

I understand that a checkbox will remain checked when you return to a page via the back button. Classes added using jquery\'s addClass however do not. Can someone help me

4条回答
  •  失恋的感觉
    2021-01-02 01:28

    It pretty much depends on the fact do you handle or not hash of the url, ie if you do, you can persist everything.

    EDITED:

    You have to be familiar with the concept of Single Page Application (SPA).

    It is all possible thanks to ability to change location hash property and manage browser history.

    In order to make this simple there are tons of libraries like Sammy.js

    Each time you have user doing an action you push new state and thus you'll be able to handle pressing of back button.

    In order to get idea of how it looks like, check following jsfiddle

    In the code you see setting up routes:

    Sammy(function() {
        this.get('#:folder', function() { ... });
        this.get('#:folder/:mailId', function() { ... });
    })).run();
    

    Which specify hash, ie www.mygreatwebsite.com/#inbox/#1 and how your app will handle it.

    There is much more going on here, so my links are just starting point for you to explore.

    EDITED: much simplier example of using sammy.js

提交回复
热议问题