Welcome Guest Search | Active Topics | Sign In | Register

How to get the HTML code of frame? Options
DarkRiDDeR
Posted: Tuesday, November 8, 2016 12:39:11 PM
Rank: Newbie
Groups: Member

Joined: 11/8/2016
Posts: 3
Hello. I load the page that contains frames. I can not understand how can I get the frame code because getHTML() does not fit. I will be grateful for the help.
eo_support
Posted: Tuesday, November 8, 2016 12:59:22 PM
Rank: Administration
Groups: Administration

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

I am not sure what you meant by "getHtml() does not fit". You can always use JavaScript code to get whatever you need and then use WebView.EvalScript to run your JavaScript code and return the value to your .NET code. See here for more details:

https://www.essentialobjects.com/doc/webbrowser/advanced/js.aspx

Thanks
DarkRiDDeR
Posted: Tuesday, November 8, 2016 2:21:02 PM
Rank: Newbie
Groups: Member

Joined: 11/8/2016
Posts: 3
Example:
Code: HTML/ASPX
<html>
<body>
...
<iframe src="http://www.site.com...">
...
</body>
</html>

After loading frame:
Code: HTML/ASPX
<html>
<body>
...
<iframe src="http://www.site.com...">
      <html>
      ...
      </html>
...
</body>
</html>

But, result of GetHTML():
Code: HTML/ASPX
<html>
<body>
...
<iframe src="http://www.site.com...">
...
</body>
</html>

I need to get frame code. Separate loading frame does not fit me.
eo_support
Posted: Tuesday, November 8, 2016 4:02:48 PM
Rank: Administration
Groups: Administration

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

You will need to use JavaScript to do that. This page should give some sample code:

http://stackoverflow.com/questions/16755347/getting-contents-of-iframe-with-pure-javascript

The above code will fail if the main page and the iframe page are from different domains. In that case you must set this property to false:

https://www.essentialobjects.com/doc/eo.webengine.browseroptions.enablewebsecurity.aspx

See here for more information on how to set browser options:

https://www.essentialobjects.com/doc/webbrowser/advanced/browser_options.aspx

Thanks!
DarkRiDDeR
Posted: Tuesday, November 8, 2016 4:34:09 PM
Rank: Newbie
Groups: Member

Joined: 11/8/2016
Posts: 3
I set browser options for the main page and the iframe page are from different domains:
Code: C#
EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions();
            options.EnableWebSecurity = false;
            webView.SetOptions(options);

I understood that. JavaScript to another iframe I can use. Example:
Code: C#
webView.EvalScript(@"
     frames[2].document.getElementsByClassName('checkbox-checkmark')[0].click();
");

If I could do something like:
Code: C#
webView.GetDOMWindow.frames[2].getHTML();

as to use JavaScript:
Code: JavaScript
frames[2].document.innerHTML

it would be very good
eo_support
Posted: Tuesday, November 8, 2016 5:01:08 PM
Rank: Administration
Groups: Administration

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

We have no plan to support this because EvalScript is much more efficient since it only involves one round trip from the .NET world to the JavaScript world, where as the other option needs a round trip on every property/method call.

Thanks!
DarkRiDDeR
Posted: Tuesday, November 8, 2016 5:21:58 PM
Rank: Newbie
Groups: Member

Joined: 11/8/2016
Posts: 3
iframe likely to relate to the structure of the html document than to JavaScript.
DarkRiDDeR
Posted: Tuesday, November 8, 2016 5:36:50 PM
Rank: Newbie
Groups: Member

Joined: 11/8/2016
Posts: 3
Although you are right, it is better to do so:
Code: C#
string frameCode = (string)webView.EvalScript("frames[2].document.innerHTML");

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.