|
Rank: Newbie Groups: Member
Joined: 3/2/2017 Posts: 3
|
Hello,
I am currently using the EO.Webbrowser in a C# project. I am trying to modify the DOM-object in order to change the appearance of a site (style parameters of some div-elements). The problem is, that the elements I want to change are not in the original html source and are rendered in iFrames I think afterwards. If I access the DOM even after waiting some seconds until I see everything is rendered I dont get the elements in the html. I tried to access every element with outerHTML, innerHTML, innerText, but I cant find what I am looking for.
If I load the page in Chrome for example and click view page source these elements are also not there BUT if I use the developer tools and list the elements for the page I can see everything.
Is there any way I can get the "real" html and modify elements so that you can see the changes when I for example change the width or height of a div-element? If there is a possibility with javascript a little example would be great as I dont have experience with that.
Greetings Peter
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, When it comes to getting the HTML, there are two important rules: 1. You will always get ONLY the current document. This means if you document contains an iframe, it will get contents outside of the iframe but not inside the iframe. This is because the contents of the iframe belongs to a different document; 2. For the current document, you will always get the rendered HTML --- there is in fact no way to get the original HTML; As such if you want to get the contents of the iframe, you must get it on the right document. The easiest way to do so is to use EvalScript to specify an iframe name: https://www.essentialobjects.com/doc/eo.webbrowser.webview.evalscript_overload_1.aspxFor example, the following code will get the HTML of the root document:
Code: C#
webView.EvalScript("document.documentElement.outerHTML", true);
The following code will get the HTML of the document inside iframe "frame1":
Code: C#
webView.EvalScript("document.documentElement.outerHTML", "frame1", true);
Note the additional "frame1" argument. You will need to change this to the actual iframe name. Hope this helps. Please feel free to let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/2/2017 Posts: 3
|
Ah great, tanks for the answer! I just tried it and it didnt work. What exactly is the name "frame1" that I put into the function. Because the iFrame I want to modify has no name- or id-tag... Does the class-attribute also work? Also it has a source-attribute, so the contents are loaded from another site. I read about cross-origin-policy issues. Is it even possible to get the content? Or should it just work? Also could you maybe give me a small js example on how to change for example the width of an element inside the iframe?
Thanks again, Peter
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
"frame1" here is the name of your iframe. Your iframe must have a name in order for it to be accessible this way. This has nothing to do with the cross-origin-policy.
|
|
Rank: Newbie Groups: Member
Joined: 3/2/2017 Posts: 3
|
Oh ok, so I cant access it that way, so I would need to use EvalScript and get the contents with pure javascript right? And does the cross origin policy than causes trouble?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Peter wrote:Oh ok, so I cant access it that way, so I would need to use EvalScript and get the contents with pure javascript right? And does the cross origin policy than causes trouble? I believe our previous replies have already answered your questions.
|
|