Rank: Member Groups: Member
Joined: 9/11/2014 Posts: 17
|
Hi admin I want to add a script into EO.WebBrowser. This's my way:
Code: C#
void wv_IsLoadingChanged(object sender, EventArgs e)
{
var webview = (WebView)sender;
if (!webview.IsLoading)
{
webview.EvalScript(GetScript());
}
}
But i don't understand why this event fire more than once with IsLoading is true, then EvalScript is called more than once. I want to prevent this thing. Please help me!
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You should use WebView.JSInitCode instead. IsLoadingChanged will be fired everytime IsLoading changes and it can change multiple times from true to false, then to true, then to false, etc. The primary purchase of IsLoadingChange is to for the UI to provide a "busy" feedback (for example, a spinning "loading" icon next to the address bar).
Please keep in mind that WebView.JSInitCode is executed for every frame. So if your HTML uses iframes, then it will be executed inside the iframes as well. You can use JavaScript to check whether window.parent is null to determine whether you are inside iframes.
Thanks!
|
Rank: Member Groups: Member
Joined: 9/11/2014 Posts: 17
|
how to use JSInitCode?
Code: C#
webcontrol.WebView.Url = "http:.....";
webcontrol.WebView.IsLoadingChanged += new EventHandler(WebView_IsLoadingChanged);
webcontrol.WebView.BeforeContextMenu += new BeforeContextMenuHandler(WebView_BeforeContextMenu);
webcontrol.WebView.JSInitCode = GetScript();
But nothing happend.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Your code is correct. However you may want to set JSInitCode before you set Url. You can try to set JSInitCode to something like "alert('hi');" to get it working and then add your own code in. JSInitCode is run with JavaScript function "eval". So it is not exactly at global space. As such you may need to adjust your code in order for it to work. You can handle this event to see if you have any JavaScript errors: http://www.essentialobjects.com/doc/eo.webbrowser.webview.consolemessage.aspxThanks!
|