I would like to run some JavaScript code in C# to clear localstorage after clicking a button in appbar in a Windows phone 7.5 app. I came across various code through Stack Overflow and forums But the specific code does not work in Windows phone app. Could you help me providing code which works in Windows Phone 7.5 app?
-
Why do you try to use JavaScript for that? C# has multiple ways to access the local storage (and clear it) which should IMO also run faster.Master117– Master1172013-06-13 06:53:26 +00:00Commented Jun 13, 2013 at 6:53
-
@Master117 Hey, I am saving some data using window.localStorage.setItem in JavaScript. The same should be cleared through JavaScript only. So, the need.user2189143– user21891432013-06-13 06:56:34 +00:00Commented Jun 13, 2013 at 6:56
-
have you tried localStorage.clear(); ?Master117– Master1172013-06-13 07:02:40 +00:00Commented Jun 13, 2013 at 7:02
-
@Master117 I can clear localstorage in JavaSript using window.localStorage.removeItem. But I need to call this JavaScript code in code behind. That is the issue.user2189143– user21891432013-06-13 08:06:36 +00:00Commented Jun 13, 2013 at 8:06
-
ah my bad, didn't think that would be the problem, cant you just call it in the event or use a delegate?Master117– Master1172013-06-13 08:18:11 +00:00Commented Jun 13, 2013 at 8:18
Add a comment
|
3 Answers
On the WebBrowser control set IsScriptEnabled to true.
In the JavaScript on the loaded page create a function to clear the storage. (For example call it "ClearStorage")
From code behind call this.webBrowser1.InvokeScript("ClearStorage");. (Adjust the name of the WebBrowser control as appropriate.)
2 Comments
Matt Lacey
"80020006" is a generic error meaning a problem with the javascript. Typically an error in the method or method not found. Can you share a minimum repro of code which shows this issue? You should also make sure you're not using a cached version of the file containing the method.