Almost working local storage

by Alin Guta

HTML

<!--1-->
<div data-role="page" id="firstpage">
    <div data-role="main" class="ui-content">
         <h1>Page 1</h1>
 <a href="#secondpage" data-role="button" class="showcontinue">Store and next</a>
 <a href="#firstmage" id="resume" data-role="button" style="display:none;">Continue</a>

    </div>
</div>
<!--2-->
<div data-role="page" id="secondpage">
    <div data-role="main" class="ui-content">
         <h1>Page 2</h1>
 <a href="#thirdpage" data-role="button" class="showcontinue">Store and next</a>
 <a href="#firstpage" data-role="button" class="showcontinue">Back to page 1</a>

    </div>
</div>
<!--3-->
<div data-role="page" id="thirdpage">
    <div data-role="main" class="ui-content">
         <h1>Page 3</h1>
 <a href="#fourthpage" data-role="button" class="showcontinue">Store and next</a>
 <a href="#firstpage" data-role="button" class="showcontinue">Back to page 1</a>

    </div>
</div>
<!--4-->
<div data-role="page" id="fourthpage">
    <div data-role="main" class="ui-content">
         <h1>Page 4</h1>
 <a href="#" data-role="button" class="showcontinue">Store</a>
 <a href="#firstpage" data-role="button" class="showcontinue">Back to page 1</a>

    </div>
</div>

JavaScript

$(document).on("pagecontainerhide", function (e, data) {
        var stored = data.toPage.attr('id');
        console.log(stored);
        localStorage.setItem('stored', stored);
        var test = localStorage.getItem('stored');
        var resume = "#" + test;
        $("#resume").attr("href", resume);
    }).on("pagecontainerbeforechange", function (e, data) {
        if (typeof data.toPage == "object" && typeof data.prevPage == "undefined" && typeof localStorage.getItem('stored') != "undefined") {
            data.toPage = "#"+localStorage.getItem('stored');
        }
        $('.showcontinue').click(function(e) {
            $('#resume').delay(300).fadeIn();
        });
    });