3

I am making a Windows 8 Phone app using HTML 5.

I am using localStorage for saving some small values as shown in the code below, I have tested my code in all browsers and it was working perfectly fine, then I created a new HTML 5 project and added my code to the project and ran the application.

In the following code, I suspect that localStorage here is not working and I wonder why ?? !

$("#cow_btn").click(function(){
    localStorage.selected_category = "cow";
    window.location.href = 'animals.html';
}); 

How did I come to this conclusion ?

1 - I tried giving alerts before and after the localStorage.selected_category = "cow"; line, here the first alert was shown but the second alert was not shown.

$("#cow_btn").click(function(){
    alert("hello1");
    localStorage.selected_category = "cow";
    alert("hello1");
    window.location.href = 'animals.html';
}); 

2 - Next I tried removing the line itself and then my window.location.href = 'animals.html';which was not working earlier now worked.

$("#cow_btn").click(function(){
    window.location.href = 'animals.html';
}); 

What could be the problem here ? My entire app works smoothly with Firefox, Chrome and even with Internet Explorer 10.

Please share your thoughts on this. How do I make the localStorage work on my HTML 5 Windows 8 Phone app ?

NOTE:

I am using the following js - jquery.min.js & jquery.mobile-1.2.0.min.js

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281

3 Answers3

3

I'm seeing the exact same behavior in my windows 8 phonegap app. The problem only occurs when using jquery mobile. Could you please try to run your app without jquery mobile?

As soon as I remove jquery mobile localstorage is working just fine.

trendt
  • 51
  • 4
2

localStorage is fully supported on WP8/IE10. To double check this try this

alert("typeof localStorage=" + typeof window.localStorage);

PS. The followign may help you to troubleshot the problem

Windows Phone 8 IE10 Javascript debugging

Community
  • 1
  • 1
Sergei Grebnov
  • 2,633
  • 18
  • 24
  • Is it supported also when serving the website from a local folder, like Cordova/Phonegap apps? At least, when I try this on desktop IE 11, it fails with a message that localStorage is not supported for local files, see this question: http://stackoverflow.com/questions/8706006/local-storage-in-ie9-fails-when-the-website-is-accessed-directly-from-the-file-s – JustAMartin May 20 '14 at 18:17
  • It seems your page is running in compatibility mode (check under F12 - dev tools or using 'navigator.userAgent'). localStaorage is fully supported for local files starting from IE10 – Sergei Grebnov May 21 '14 at 05:23
  • I just opened a local html file which tries to access localStorage on IE 11 and I made sure that in F12 Dev Tools Docuemnt mode is Edge (default), and Browser Profile is Desktop. Still, I got `undefined` error for localStorage. But the same file opened without errors when served from localhost. Maybe Microsoft has disabled it again on IE 11. – JustAMartin May 24 '14 at 17:44
-2

Windows Phone will not support your coding style. Be sure to use the setItem / getItem commands, as in WP8/IE10 the localStorage.key = value; commands are not supported even tough they are W3C standard.

Mike
  • 9