so have home page created using html. run off computer opening html file. i'm trying add feature allows me edit page (using content-editable
or append
), not source code. achieve this, came using localstorage
hold updated version of webpage, , loading page updated version. see here. (theoretically, periodically update source code localstorage
version it's matched up.)
however, when tried it, page won't update. have version saved localstorage
, seems if program can't overwrite version, or similar.
my html looks this:
<!doctype html> <html> <head> <title>scss | projects</title> <link type="text/css" rel="stylesheet" href="home page heading style.css"> <link type="text/css" rel="stylesheet" href="home page projects style.css"> <script type="text/javascript" src="save script.js"></script> <script type="text/javascript" src="jquery.js"></script> </head> <body onload="checkedits()"> <div id="everything"> <div class="box"> <a href="who i.html"><div class="img"><img src="who i.png" /></div></a> <div class="wrapper"> <div class="title">who i?</div> <div class="description">a project english class describing through different medias , explained unit questions.</div> </div> <div class="notes" contenteditable="true">complete.</div> </div> <a href="#" class="back-to-top" onclick="saveedits()">s</a> </div><!--end everything--> </body>
my javascript looks this:
function saveedits() { //get editable element var edited = document.getelementbyid("everything"); //get edited element content var userversion = edited.innerhtml; //save content local storage var localstorage.edits = userversion; } function checkedits() { //find out if user has saved edits if(localstorage.edits != null) document.getelementbyid("everything").innerhtml = localstorage.edits; }
but page doesn't work right; doesn't load updated version. viewing localstorage
, seems if it's not saving properly.
why doesn't work? how can fix it? there conceptually incorrect plan? appreciated; thanks!
for localstorage
can get/setitem
e.g.
function saveedits() { //get editable element var edited = document.getelementbyid("everything"); //get edited element content var userversion = edited.innerhtml; //save content local storage localstorage.setitem('edits', userversion); } function checkedits() { //find out if user has saved edits var savededits = localstorage.getitem('edits'); if (savededits != null) { document.getelementbyid("everything").innerhtml = savededits; } }
https://developer.mozilla.org/en-us/docs/web/api/storage
you might notice jquery not used/required code...
Comments
Post a Comment