Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-12-2012, 10:52 AM
PM User |
#1
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 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?
__________________
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
02-12-2012, 01:57 PM
PM User |
#3
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Quote:
Originally Posted by
devnull69
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.
02-12-2012, 09:05 PM
PM User |
#4
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 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>
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8%
IE10:10%
Last edited by rnd me; 02-12-2012 at 09:19 PM ..
Users who have thanked rnd me for this post:
02-13-2012, 07:07 AM
PM User |
#5
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
Thanks, this is a very helpful post!
02-01-2013, 06:20 PM
PM User |
#6
New Coder
Join Date: Jan 2009
Posts: 12
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.
02-01-2013, 06:27 PM
PM User |
#7
Regular Coder
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 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".
02-01-2013, 07:46 PM
PM User |
#8
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 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.
02-04-2013, 06:10 PM
PM User |
#9
New Coder
Join Date: Jan 2009
Posts: 12
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>
02-05-2013, 11:34 AM
PM User |
#10
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8%
IE10:10%
02-06-2013, 10:12 AM
PM User |
#11
New to the CF scene
Join Date: Feb 2013
Posts: 3
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.
04-26-2013, 04:06 PM
PM User |
#12
Senior Coder
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
Quote:
Originally Posted by
rnd me
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?
04-26-2013, 04:26 PM
PM User |
#13
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8%
IE10:10%
04-26-2013, 06:29 PM
PM User |
#14
Senior Coder
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 01:07 AM .
Advertisement
Log in to turn off these ads.