CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   HTML5 / IE9 Local Storage (http://www.codingforums.com/showthread.php?t=251374)

Philip M 02-12-2012 10:52 AM

HTML5 / IE9 Local Storage
 
I run Windows 7 and IE9, and I believe IE9 supports HTML5 Local Storage. But when I run this offline (locally) in IE9

Code:

<script type="text/javascript">

function testSupport() { 
if (localStorage)  {return "Local Storage: Supported"}
else  {
return "Local Storage: NOT supported"; 
}
}

alert ( testSupport() );
</script>

I get "LocalStorage: NOT supported".

Chrome returns "Local Storage: Supported"

My DOCTYPE is <!DOCTYPE html>


Other tests also fail in IE. Example:

Code:

localStorage.setItem("name", "Hello World!");
alert(localStorage.getItem("name"));

Above works in Chrome.
Any advice, please? Have I not configured IE9 properly?

devnull69 02-12-2012 12:59 PM

As far as I can see IE doesn't support localStorage for local files

See: http://stackoverflow.com/questions/8...rom-the-file-s

Philip M 02-12-2012 01:57 PM

Quote:

Originally Posted by devnull69 (Post 1192185)
As far as I can see IE doesn't support localStorage for local files

See: http://stackoverflow.com/questions/8...rom-the-file-s

Yeah, that is my conclusion as well!

rnd me 02-12-2012 09:05 PM

use userData persistence for up to 640kb of storage. not 5mb, but a lot better than 4-8kb!


use store(st_req_key, str_opt_val) to store things xbrowser using localStorage, globalStorage, userData, or cookies (fallbacks).

Code:

<html><head> 



<script type="text/javascript" src="http://danml.com/mini/"></script>

<script type="text/javascript">

  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>



without a lib:
Code:

<html><head> 





<script type="text/javascript">
var store=function(){
function el(tid) {return document.getElementById(tid);}
if(!window.globalStorage && window.localStorage){
        window.globalStorage={};
      globalStorage[document.domain]=window.localStorage;
}//end webkit+ie8  patch
function setCookie(nm, valu) {var e2 = (new Date(2019, 1, 1)).toGMTString();document.cookie = nm + "=" + escape(valu) + "; expires=" + e2;};
function getCookie(k){var d = document.cookie || "";var pairs = d.split(k + "=");if (pairs && pairs[1]) {return unescape(pairs[pairs.length-1].split(";")[0]);}}
if(window.globalStorage){function store(key,val){if(val){globalStorage[document.domain][key]=val;}else{
  try{var tm=globalStorage[document.domain][key];if(tm){tm=tm.toString();}}catch(rr){return"";}return tm;}return;}
}else{
  var store=function (key,val){if(val){setCookie(key,val);}else{return getCookie(key);}}
}
function iestorer(){
 var D=document;if(!D.createStyleSheet||window.localStorage){return;}
  var tCSS=D.createStyleSheet();tCSS.addRule(".userData","behavior:url(#default#userdata)",0);var Static=D.createElement("input");var Q=function(z,x){Static.setAttribute(z,x);};Q("type","hidden");Q("id","EzStatic420");Q("className","userData");document.getElementsByTagName("head")[0].appendChild(Static);var s=el("EzStatic420");function ies(k,v){if(!v){s.load("oXMLStore");var t=s.getAttribute(k);return unescape(t)||"";}else{s.setAttribute(k,escape(String(v)));s.save("oXMLStore");}}
  store=window.store=ies;
};iestorer();
return store;
}());





  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>


devnull69 02-13-2012 07:07 AM

Thanks, this is a very helpful post!

RCGUA 02-01-2013 06:20 PM

IE 9 local file not from server
 
Doesn't seem work with IE9 when the htm file is located on a desktop hard drive and not on a server. Works fine with IE7 and IE8, when the file is on the hard drive.

WolfShade 02-01-2013 06:27 PM

If I may offer the following (works in IE7/8 on a server, not sure about 9):

Code:

var storage, fail, uid;
try{
  uid = new Date();
  storage = window.localStorage;
  storage.setItem(uid,uid);
  fail = storage.getItem(uid) != uid;
  storage.removeItem(uid);
  fail && (storage = false);
  }catch(e){}

if(storage){ alert("Storage YES"); } else { alert("Nope.. ain't happenin'"); }


Philip M 02-01-2013 07:46 PM

In IE9 locally I get

Nope.. ain't happenin' :(

RCGUA 02-04-2013 06:10 PM

IF you have access to a server that you can put the file on, you can make a file which you can run on the local hard drive with an iframe that points to the file on the server, it works fine in IE9, but you do need to be connected to the Internet, not offline.

Code:

<html>
<head></head>
<body>
<iframe src="http://www.myWebPage.html" width="800px" height="250px" seamless="seamless" frameborder="0"></iframe>
</body>
</html>


rnd me 02-05-2013 11:34 AM

if you;re local in IE9, localStorage won't work. you have dom storage behaviors, and that's it. You can however read and write files by renaming the html file to .hta. I actually had an app that saved a json blob inside it's own hta file: to save it would load itself, split the file apart at the json section, sandwich in the new json stringification, and save the hta file over itself. A little different i realize, but it did the job i needed it too.

Rexsrambo 02-06-2013 10:12 AM

HTML 5 will be the new standard for HTML. HTML 5 is still a work in progress. However, the major browsers support many of the new HTML 5 elements and APIs.

jmrker 04-26-2013 04:06 PM

Quote:

Originally Posted by rnd me (Post 1192345)
use userData persistence for up to 640kb of storage. not 5mb, but a lot better than 4-8kb!


use store(st_req_key, str_opt_val) to store things xbrowser using localStorage, globalStorage, userData, or cookies (fallbacks).

Code:

<html><head> 



<script type="text/javascript" src="http://danml.com/mini/"></script>

<script type="text/javascript">

  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>



without a lib:
Code:

<html><head> 





<script type="text/javascript">
var store=function(){
function el(tid) {return document.getElementById(tid);}
if(!window.globalStorage && window.localStorage){
        window.globalStorage={};
      globalStorage[document.domain]=window.localStorage;
}//end webkit+ie8  patch
function setCookie(nm, valu) {var e2 = (new Date(2019, 1, 1)).toGMTString();document.cookie = nm + "=" + escape(valu) + "; expires=" + e2;};
function getCookie(k){var d = document.cookie || "";var pairs = d.split(k + "=");if (pairs && pairs[1]) {return unescape(pairs[pairs.length-1].split(";")[0]);}}
if(window.globalStorage){function store(key,val){if(val){globalStorage[document.domain][key]=val;}else{
  try{var tm=globalStorage[document.domain][key];if(tm){tm=tm.toString();}}catch(rr){return"";}return tm;}return;}
}else{
  var store=function (key,val){if(val){setCookie(key,val);}else{return getCookie(key);}}
}
function iestorer(){
 var D=document;if(!D.createStyleSheet||window.localStorage){return;}
  var tCSS=D.createStyleSheet();tCSS.addRule(".userData","behavior:url(#default#userdata)",0);var Static=D.createElement("input");var Q=function(z,x){Static.setAttribute(z,x);};Q("type","hidden");Q("id","EzStatic420");Q("className","userData");document.getElementsByTagName("head")[0].appendChild(Static);var s=el("EzStatic420");function ies(k,v){if(!v){s.load("oXMLStore");var t=s.getAttribute(k);return unescape(t)||"";}else{s.setAttribute(k,escape(String(v)));s.save("oXMLStore");}}
  store=window.store=ies;
};iestorer();
return store;
}());





  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>



As best as I can determine, you seem to have one extra ')' character at the end of the definition for the script without a library.
Code:

}());

  store("something", "with data");

Have I miss counted?

rnd me 04-26-2013 04:26 PM

fully formed and exported:
Code:

(function() {

  var D=document;

        function setCookie(nm, valu) {
                var e2 = (new Date(2019, 1, 1)).toGMTString();
                document.cookie = nm + "=" + escape(valu) + "; expires=" + e2;
        }


        function getCookie(k) {
                var d = D.cookie || "";
                var pairs = d.split(k + "=");
                if (pairs && pairs[1]) {
                        return unescape(pairs[pairs.length - 1].split(";")[0]);
                }
        }


        if (window.localStorage&& !location.protocol.match("data")) {
                function store(key, val) {
                        if (val) {
                                localStorage[key] = val;
                        } else {
                                try {
                                        var tm = localStorage[key];
                                        if (tm) {
                                                tm = tm.toString();
                                        }
                                } catch (rr) {
                                        return "";
                                }
                                return tm;
                        }
                        return;
                }
        } else {
                var store = function(key, val) {
                        if (val) {
                                setCookie(key, val);
                        } else {
                                return getCookie(key);
                        }
                }
        }

        function iestorer() {
                var D = document;
                if (!D.createStyleSheet || window.localStorage) {
                        return;
                }
                var tCSS = D.createStyleSheet();
                tCSS.addRule(".userData", "behavior:url(#default#userdata)", 0);
                var Static = D.createElement("input");
                var Q = function(z, x) {
                        Static.setAttribute(z, x);
                };
                Q("type", "hidden");
                Q("id", "EzStatic420");
                Q("className", "userData");
                document.getElememntsByTagName("head")[0].appendChild(Static);
                var s = Static;

                function ies(k, v) {
                        if (!v) {
                                s.load("oXMLStore");
                                var t = s.getAttribute(k);
                                return unescape(t) || "";
                        } else {
                                s.setAttribute(k, escape(String(v)));
                                s.save("oXMLStore");
                        }
                }
                window.store = ies;
        }
        iestorer();

        window.store = store;
}());


use:
READ: store(key)
WRITE: store(key, value)

jmrker 04-26-2013 06:29 PM

OK, I see the problem...

In post #4, it starts out as:
Code:

<script type="text/javascript">
var store=function(){
...

In your last post #13, it starts as:
Code:

(function() {

  var D=document;
...

The missing '(' was at the start of the anonymous function.

I was getting an error with post #4 because of the extra ')'.

Works fine with latest change.
I assume problem had to do with the set-up at the start of post #4 where you did not use the initial '(' character.


All times are GMT +1. The time now is 09:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.