javascript - How can I store persistent data with JS/JQuery using the file:/// protocol and IE/Edge browser? -
i'm writing small web page application users can dynamically drag , drop links files , pages on customisable homepage.
it written in html5 , javascript/jquery mobile. page stored on local machine , accessed 'file:///' protocol, using internet explorer / microsoft edge webbrowser.
i'm trying find way store data resembles customized page , links, when user opens page again links still there , can edited , customized further.
so far i've been looking html localstorage, doesn't work ie/edge through 'file:///' protocol, page not hosted. thinking of creating file data in there, don't believe possible either due security reasons.
i have not alot of experience javascript, appreciated!
if want work on internet explorer/microsoft edge, simple way persist data using cookies. work using file:// protocol, , thing setting far away expiration date (in example below: 2/2/2222).
try sample code (part of comes this site) count number of times page has been loaded. notice how counter kept after closing browser , reopening it:
<!doctype html> <html> <head> <title>persistent data cookies in ie</title> </head> <body> number of reloads: <span id="num">-</span> <script> function setcookie(name, value) { var expiry = new date(2222,2,2); document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.togmtstring(); } function getcookie(name) { var re = new regexp(name + "=([^;]+)"); var value = re.exec(document.cookie); return (value != null) ? unescape(value[1]) : null; } var cookieval = getcookie("num"); var num = cookieval != null ? cookieval : 0; document.getelementbyid("num").innerhtml = num; setcookie("num", parseint(num) + 1) </script> </body> </html> pros of solution:
- simple , easy implement.
- works
file://protocol in ie , edge (as specified in question) , in firefox.
cons of solution:
- limited storage space.
- doesn't work
file://protocol in chrome (not required in question).
Comments
Post a Comment