Data retention in return



  • There is a sequence of 4 pages html: main_page, day_page, para_page, name_page. It's working on the pages, but when the Android presses кнопку назад the data are not retained.

    How to solve the problem with js or jquery



  • If you need to keep the data in the fields, you can use something like this:

    $(function() {
      function serialize() {
        var obj = {};
    
    $('input[type="text"]').each(function(id, el) {
      var $el = $(el);
      obj[$el.attr('name')] = $el.val();
    });
    
    sessionStorage.setItem('data', JSON.stringify(obj));
    

    }

    function deserialize() {
    console.log(sessionStorage.getItem('data'))
    var obj = JSON.parse(sessionStorage.getItem('data', '{}'));

    for (var i in obj) {
      if (!obj.hasOwnProperty(i)) continue;
    
      $('input[name="' + i + '"]').val(obj[i]);
    }
    

    }

    $('input[type="text"]').change(function() {
    serialize();
    });

    deserialize();
    });

    https://jsfiddle.net/vntekhm1/2/




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2