admin管理员组文章数量:1026989
I am getting an error in internet explorer 11
"Unable to get property 'length' of undefined or null reference" on line
if (window.localStorage.length !== 0)
it works fine on chrome and Firefox, not sure whats causing it
<script>
function initialize() {
// test to see if brouser supports storeage api
var bSupportsLocal = (('localStorage' in window) && window.localStorage !== null );
if (!bSupportsLocal) {
document.getElementById('infoform').innerHTML = "<p> Sorry, This browser does not suport local storage. </p>";
return;
}
if (window.localStorage.length !== 0) {
document.getElementById('firstName').value = window.localStorage.getItem('firstName');
$.mobile.navigate("#benefits-facts");
}
}
function storeLocalContent(fName) {
window.localStorage.setItem('firstName', fName);
}
function clearLocalContent(strToStore) {
window.localStorage.clear();
}
window.onload = initialize;
</script>
I am getting an error in internet explorer 11
"Unable to get property 'length' of undefined or null reference" on line
if (window.localStorage.length !== 0)
it works fine on chrome and Firefox, not sure whats causing it
<script>
function initialize() {
// test to see if brouser supports storeage api
var bSupportsLocal = (('localStorage' in window) && window.localStorage !== null );
if (!bSupportsLocal) {
document.getElementById('infoform').innerHTML = "<p> Sorry, This browser does not suport local storage. </p>";
return;
}
if (window.localStorage.length !== 0) {
document.getElementById('firstName').value = window.localStorage.getItem('firstName');
$.mobile.navigate("#benefits-facts");
}
}
function storeLocalContent(fName) {
window.localStorage.setItem('firstName', fName);
}
function clearLocalContent(strToStore) {
window.localStorage.clear();
}
window.onload = initialize;
</script>
Share
Improve this question
edited Aug 10, 2015 at 3:07
Lee Taylor
7,99416 gold badges37 silver badges53 bronze badges
asked Aug 9, 2015 at 21:20
brodsterbrodster
771 gold badge2 silver badges13 bronze badges
5
- didi you try to remove one equal sign? window.localStorage !== null – EugenSunic Commented Aug 9, 2015 at 21:21
- if i remove one equal sign i get "Sorry, This browser does not support local storage." – brodster Commented Aug 9, 2015 at 21:37
- I believe this could help you: stackoverflow./questions/21155137/… – EugenSunic Commented Aug 9, 2015 at 21:52
- that is not the problem, I am running the latest versions of IE 11 – brodster Commented Aug 9, 2015 at 22:06
-
@brodster Are you perhaps accessing the page with
file://
? Or, have you checked the document mode that's in use? The page may be running under a patibility mode that doesn't support web storage. – Jonathan Lonowski Commented Aug 10, 2015 at 2:31
1 Answer
Reset to default 1I thought in IE window.localStorage
is undefined initially. You are checking is localStorage
in the window
and its not null
. So bSupportLocal
is setting to true. Its executing window.localStorage.length
statement. Undefined.length causing error.
Here is the code
var bSupportsLocal = window['localStorage'] || '';
If localStorage is having some value it will assign to bSupportsLocal, otherwise it is assigned with empty string.
I am getting an error in internet explorer 11
"Unable to get property 'length' of undefined or null reference" on line
if (window.localStorage.length !== 0)
it works fine on chrome and Firefox, not sure whats causing it
<script>
function initialize() {
// test to see if brouser supports storeage api
var bSupportsLocal = (('localStorage' in window) && window.localStorage !== null );
if (!bSupportsLocal) {
document.getElementById('infoform').innerHTML = "<p> Sorry, This browser does not suport local storage. </p>";
return;
}
if (window.localStorage.length !== 0) {
document.getElementById('firstName').value = window.localStorage.getItem('firstName');
$.mobile.navigate("#benefits-facts");
}
}
function storeLocalContent(fName) {
window.localStorage.setItem('firstName', fName);
}
function clearLocalContent(strToStore) {
window.localStorage.clear();
}
window.onload = initialize;
</script>
I am getting an error in internet explorer 11
"Unable to get property 'length' of undefined or null reference" on line
if (window.localStorage.length !== 0)
it works fine on chrome and Firefox, not sure whats causing it
<script>
function initialize() {
// test to see if brouser supports storeage api
var bSupportsLocal = (('localStorage' in window) && window.localStorage !== null );
if (!bSupportsLocal) {
document.getElementById('infoform').innerHTML = "<p> Sorry, This browser does not suport local storage. </p>";
return;
}
if (window.localStorage.length !== 0) {
document.getElementById('firstName').value = window.localStorage.getItem('firstName');
$.mobile.navigate("#benefits-facts");
}
}
function storeLocalContent(fName) {
window.localStorage.setItem('firstName', fName);
}
function clearLocalContent(strToStore) {
window.localStorage.clear();
}
window.onload = initialize;
</script>
Share
Improve this question
edited Aug 10, 2015 at 3:07
Lee Taylor
7,99416 gold badges37 silver badges53 bronze badges
asked Aug 9, 2015 at 21:20
brodsterbrodster
771 gold badge2 silver badges13 bronze badges
5
- didi you try to remove one equal sign? window.localStorage !== null – EugenSunic Commented Aug 9, 2015 at 21:21
- if i remove one equal sign i get "Sorry, This browser does not support local storage." – brodster Commented Aug 9, 2015 at 21:37
- I believe this could help you: stackoverflow./questions/21155137/… – EugenSunic Commented Aug 9, 2015 at 21:52
- that is not the problem, I am running the latest versions of IE 11 – brodster Commented Aug 9, 2015 at 22:06
-
@brodster Are you perhaps accessing the page with
file://
? Or, have you checked the document mode that's in use? The page may be running under a patibility mode that doesn't support web storage. – Jonathan Lonowski Commented Aug 10, 2015 at 2:31
1 Answer
Reset to default 1I thought in IE window.localStorage
is undefined initially. You are checking is localStorage
in the window
and its not null
. So bSupportLocal
is setting to true. Its executing window.localStorage.length
statement. Undefined.length causing error.
Here is the code
var bSupportsLocal = window['localStorage'] || '';
If localStorage is having some value it will assign to bSupportsLocal, otherwise it is assigned with empty string.
本文标签: javascriptIE 11 Unable to get property 39length39 of undefined or null referenceStack Overflow
版权声明:本文标题:javascript - IE 11 Unable to get property 'length' of undefined or null reference - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745652946a2161428.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论