php - localStorage cleared after refresh -
i have problem saving data localstorage of browser.
i have php file , switch. when type "favorites" make create button , send json data function "save" in 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 favorites</span> </a>"; break;
this javascript:
function save(data) { var thedata = data; // store above data in localstorage localstorage.setitem('data', "testje"); }
i'm testing text "testje". when push button goes in localstorage when refresh page gone ...
does anbody know how comes?
you using html attribute transport value albeit not html encoding of value. break code. if verify html source code might have seen that. validate first (install browser-extension automatically).
also written need html encode onclick attribute value:
echo "<a onclick='save(", htmlspecialchars($data), ")' s [...] ^^^^^^^^^^^^^^^^
Comments
Post a Comment