|
Rank: Newbie Groups: Member
Joined: 5/6/2020 Posts: 2
|
So in my windows forms i have a Webcontrol and Webview. What i am trying to achieve is to set a localstorage item in the webbrowser.
My current code is this but it doesnt work:
webView1.QueueScriptCall("localStorage.setItem('token', 'agit');"); webView1.QueueScriptCall("alert(localStorage.getItem('token'));");
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
We tested your code with the latest build and it works fine. Note that localStorage is always associated to an "origin". So you won't be able to run the code without an origin. For example, when the WebView has just loaded a blank page (about:blank), you won't be able to use localStorage because this is not a valid origin that can have localStorage. You can also use the DevTools console to see if you can find any error message.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 5/6/2020 Posts: 2
|
And how can i assign localStorage to an origin?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
You do not assign localStorage an origin. The origin is automatically determined by the Url you loaded into the WebView. That's exactly why it's called localStorage. For example, if you load "www.google.com" and set localStorage, then everything you set would be associated to "google.com". Later when you load "www.yahoo.com", the localStorage you previously set for "google.com" won't be visible now since the current origin is "yahoo.com".
|
|