Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts

    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?
    Last edited by Philip M; 02-12-2012 at 12:12 PM. Reason: Amplified

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    As far as I can see IE doesn't support localStorage for local files

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

  • Users who have thanked devnull69 for this post:

    Philip M (02-12-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by devnull69 View Post
    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!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,444
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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>
    Last edited by rnd me; 02-12-2012 at 10:19 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    devnull69 (02-13-2012)

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Thanks, this is a very helpful post!

  • #6
    New Coder
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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.

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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'"); }
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    In IE9 locally I get

    Nope.. ain't happenin'

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    New Coder
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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>

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,444
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #11
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,130
    Thanks
    38
    Thanked 504 Times in 498 Posts

    Question

    Quote Originally Posted by rnd me View Post
    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?

  • #13
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,444
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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)
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #14
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,130
    Thanks
    38
    Thanked 504 Times in 498 Posts

    Thumbs up

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •