Welcome Guest Search | Active Topics | Sign In | Register

Reload of webview doesn't retain javascript object set from c# wpf Options
CodePlayer
Posted: Tuesday, April 21, 2015 3:46:06 PM
Rank: Member
Groups: Member

Joined: 4/21/2015
Posts: 14
I am using 3.0.112.0 version EO.WebBrowser.WPF in my wpf application. Application has a window with eo:webcontrol/webview. when app starts window is launched with specific URL and javascript object is embedded using QueueScriptCall. All this works fine. Problem arise when url in the same webview is changed. The new page loaded doesn't retain javascript that was was added in the first call. I tried doing in UrlChanged event and that didn't work either. Am I doing something wrong.
Here's the code snippet where webview is initialized when window is launched first time
webVw.BeforeRequestLoad += new BeforeRequestLoadHandler(this.OnBeforeRequestLoad);
RegisterJSFunctions(); // registering c# method to be invoked
webVw.QueueScriptCall(GetQueueScript()); // adding javascript string
webVw.ScriptCallDone += new ScriptCallDoneHandler(this.OnQueueScriptCallDone);
webVw.ConsoleMessage += new ConsoleMessageHandler(this.OnConsoleMessage);
webVw.Closed += new EventHandler(this.OnViewClosed);
webVw.Url = this.EOWebViewURL;
eo_support
Posted: Tuesday, April 21, 2015 5:16:32 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

A JavaScript object always lives in the context of a window and a document object. When a page is reloaded, both objects are refreshed, so JavaScript objects never out live a page (this is why there are other things such as cookies). Using a different browser engine, or a different wrapper such as EO.WebBrowser will not change this rule.

One thing you can consider is to set WebView.JSInitCode. This is a piece of JavaScript code that will be called everytime a new page is loaded. Inside your JSInitCode you can run your additional JavaScript code. Because it will be called everytime a new page is loaded, so you can recreate your object this way.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
CodePlayer
Posted: Tuesday, April 21, 2015 10:15:42 PM
Rank: Member
Groups: Member

Joined: 4/21/2015
Posts: 14
I will try using JSInitCode. It makes sense..but I had been using Awesomium for quite some time JS global variable I created on initialization stayed through out the life of the page no matter refreshed or reloaded.

Do I also need to need to register RegisterJSExtensionFunction again when page is refreshed in existing webview?
CodePlayer
Posted: Tuesday, April 21, 2015 10:20:22 PM
Rank: Member
Groups: Member

Joined: 4/21/2015
Posts: 14
I was able to figure out ..I don't have to re register JSExtensionFunction on reload and your solution worked..thanks
eo_support
Posted: Tuesday, April 21, 2015 10:35:52 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Great. Glad to hear that you got it working!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.