Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2012, 10:52 AM   PM User | #1
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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?
__________________

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.

Last edited by Philip M; 02-12-2012 at 11:12 AM.. Reason: Amplified
Philip M is offline   Reply With Quote
Old 02-12-2012, 12:59 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
As far as I can see IE doesn't support localStorage for local files

See: http://stackoverflow.com/questions/8...rom-the-file-s
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
Philip M (02-12-2012)
Old 02-12-2012, 01:57 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-12-2012, 09:05 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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>
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%

Last edited by rnd me; 02-12-2012 at 09:19 PM..
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
devnull69 (02-13-2012)
Old 02-13-2012, 07:07 AM   PM User | #5
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Thanks, this is a very helpful post!
devnull69 is offline   Reply With Quote
Old 02-01-2013, 06:20 PM   PM User | #6
RCGUA
New Coder

 
Join Date: Jan 2009
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
RCGUA is an unknown quantity at this point
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.
RCGUA is offline   Reply With Quote
Old 02-01-2013, 06:27 PM   PM User | #7
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 02-01-2013, 07:46 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-04-2013, 06:10 PM   PM User | #9
RCGUA
New Coder

 
Join Date: Jan 2009
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
RCGUA is an unknown quantity at this point
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>
RCGUA is offline   Reply With Quote
Old 02-05-2013, 11:34 AM   PM User | #10
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 02-06-2013, 10:12 AM   PM User | #11
Rexsrambo
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rexsrambo is an unknown quantity at this point
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.
Rexsrambo is offline   Reply With Quote
Old 04-26-2013, 04:06 PM   PM User | #12
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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?
jmrker is offline   Reply With Quote
Old 04-26-2013, 04:26 PM   PM User | #13
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 04-26-2013, 06:29 PM   PM User | #14
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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.
jmrker is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 AM.


Advertisement
Log in to turn off these ads.