I have a problem with saving data to the localstorage of the browser.
I have a php file and a switch. When the type is "favorites" I make a create a button and send the json data to a function "save" in my javascript.
case 'favorites':
$session = $m->session;
$data = json_encode((array)$session);
echo "<a onclick='save(".$data.")' style='cursor:pointer;' class='metacell'>
<img src='".buildUri('images/icons/favorite.png')."' width='16' />
<span>Add to favorites</span>
</a>";
break;
This is my javascript:
function save(data)
{
var thedata = data;
// STORE THE ABOVE DATA IN LOCALSTORAGE
localStorage.setItem('data', "testje");
}
I'm currently testing with just some text "testje". When i push the button it goes in localstorage but when I refresh the page its gone ...
Does anbody know how this comes?