3
votes

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

3

3 Answers

3
votes

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.

2
votes

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

-2
votes

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.