javascriptjqueryhtmllocal-storageoverscroll

How to store and then load content via html5 storage api?


1 - I have this map: WATCH!

2 - HOW to store map position with HTML5 storage, when i have this code:

var PlanetRefreshTimeSec = 1;//planet refresh time in seconds..
function loadData() {
    $("#show_planet_realtime").load("../in/GameEngine/RealTimeRender.php?p=<?php echo $player; ?>", function () {
        setTimeout( function () {
            loadData();
        }, PlanetRefreshTimeSec * 1000);
    });
}
$( function () {
    loadData();
});

I have written this code, but it seems not working.. :

var PlanetRefreshTimeSec = 1;//planet refresh time in seconds..
function loadData() {

    $.ajaxSetup({
        cache: false
    });

    var updatePosition = function() {
        var div = $('#show_planet_realtime');
        setTimeout(function(){div.scrollTop(div.height())},200);
    };
    $("#show_planet_realtime").load("../in/GameEngine/RealTimeRender.php?p=<?php echo $player; ?>", updatePosition, function () {
        setTimeout( function () {
            loadData();
        }, PlanetRefreshTimeSec * 1000);
    });
}
$( function () {
    loadData();
});

Please tell me, how to make map position keep at coords while page is being refreshed?


Solution

  • after load, you could save coords this way:

    localStorage.setItem("coords-player23423", coords);
    

    And after reload setup coords to those in storage

    var coords = localStorage.getItem("coords-player23423");
    player.updateCoords( coords );