Welcome Guest Search | Active Topics | Sign In | Register

Change the HTML of a page Options
hmireault
Posted: Tuesday, July 15, 2014 9:02:01 AM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 52
Hello,

I know that, using the webView's "evalscript" function, I can execute Javascript which can change the inner HTML of a webpage.

I was wondering if it was possible to directly change the HTML that the webView contains. I can do that with a System.Windows.Forms.WebBrowser object by doing this:

Code: C#
HtmlDocument htmlDocument = webBrowser.Document;
    List<HtmlElement> elements = htmlDocument.All.Cast<HtmlElement>().Where( CONDITION ).ToList();

    foreach (HtmlElement element in elements)
    {
          element.SetAttribute("value", myValue);
    }


Basically, is there an equivalent to the System.Windows.Forms.WebBrowser's "Document" property that I could edit in such a way in EO.WebBrowser?

Thanks in advance.
eo_support
Posted: Tuesday, July 15, 2014 5:29:50 PM
Rank: Administration
Groups: Administration

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

You can do that with something like this:

Code: C#
//Get document.all collection
JSObject all = webView1.GetDOMWindow().document["all"] as JSObject;

//Get number of items in the collection
int length = (int)all["length"];

//Loop through each item and set the property value
for (int i = 0; i < length; i++)
{
    JSObject item = all[i.ToString()] as JSObject;
    item["value"] = myValue;
}


The code is slightly more cumbersome than the IE version. We are adding a few methods in our next build so that you will be able to use code like this in the next build:

Code: C#
//Get document.all collection
JSArray all = (webView1.GetDOMWindow().document["all"] as JSObject).ToArray();

//Loop through each item and set the property value
for (int i = 0; i < all.Length; i++)
{
    JSObject item = all[i] as JSObject;
    item["value"] = myValue;
}


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

Thanks!
hmireault
Posted: Wednesday, July 16, 2014 8:30:47 AM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 52
We opted to use Javascript in this case, but this will be useful in the future.

Thank you very much for your quick reply!
eo_support
Posted: Wednesday, July 16, 2014 9:17:10 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
You are very welcome. Please feel free to let us know if there is anything else.

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.