3

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?

5
  • 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. Commented 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. Commented Jun 13, 2013 at 6:56
  • have you tried localStorage.clear(); ? Commented 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. Commented 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? Commented Jun 13, 2013 at 8:18

3 Answers 3

1

You Just clear the

Cookies and Web Browser Cache

YourWebBrowserControl.ClearCookiesAsync();

YourWebBrowserControl.ClearInternetCacheAsync();

Sign up to request clarification or add additional context in comments.

Comments

0

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

tried. But getting "An unknown error has occurred. Error: 80020006."
"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.
0

After load the web page, when LoadCompleted event has raised, call InvokeScript. If you do that before, the application throws exception with error code 80020006.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.