Welcome Guest Search | Active Topics | Sign In | Register

prevent eval script more than once Options
Minh Giang
Posted: Friday, June 26, 2015 3:55:11 AM
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!
eo_support
Posted: Friday, June 26, 2015 10:56:44 AM
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!
Minh Giang
Posted: Friday, June 26, 2015 11:35:28 PM
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.
eo_support
Posted: Monday, June 29, 2015 11:30:20 AM
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.aspx

Thanks!


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.