Use webbrowser to obtain HTML page content in the framework

Source: Internet
Author: User

Using webbrowser to retrieve pages is relatively simple, and there is an example in msdn. You don't need to mention it here.

However, some HTML documents are composed of "frameworks", or they can store their own unique HTML document windows. You can use a framework to easily create HTML pages. One or more pages of an HTML page remain static while other frameworks continuously change their content, such as the navigation bar.

HTML authors can use either of the following two methods to create a framework:

    • UseFramesetAndFrameTag to create a fixed window.

-Or-

    • UseIFRAMETag to create a floating window that can be replaced at runtime.

    1. Because frameworks contain HTML documents, they are represented as window elements and framework elements in the Document Object Model (DOM.

    2. When using the htmlwindow framework set to accessFrameOrIFRAMETag, that is, to retrieve the window elements corresponding to this framework. All the dynamic attributes of the framework, such as its current URL, document, and size.

    3. UseHtmlwindow, Children collection, getelementsbyname, getelementbyid, and other methods.FrameOrIFRAMEWhen marking, that is, retrieving framework elements. This refers to the static attributes of the framework, including the URLs specified in the original HTML file.

Framework and security

Access to the framework is complicated because the security measures hosted by HTML Dom are called "cross-framework scripting Security. If the document containsFramesetTwo or moreFrameIn different domainsFrameCannot interact with each other. In other wordsFrameUnable to access hosts third-party sites such as http://www.adatum.com/Frame. InHtmlwindowClass-level security. You can obtainFrameBut cannot access its document or change its host.FrameOrIFRAME.

This rule also applies to Windows opened using the open and opennew methods. If the domain of the window you open is different from the domain of the page hosted in the webbrowser control, you cannot move the window or check its content. When you useWebbrowserDisplay and deploy an application based on Windows FormsProgramThese restrictions are also enforced when different websites are used. If you use the clickonce deployment technology to install applications from website a, useWebbrowserIf website B is displayed, you cannot access the data of website B.

For more information about cross-site scripting, see about cross-frame scripting and Security (about cross-framework scripting and security) (http://msdn.microsoft.com/library/default.asp? Url =/Workshop/author/OM/xframe_scripting_security.asp ).

See Other resources

Use the managed HTML Document Object Model
Frame Element | frame object

1. Get the source file of the frame.

MessageBox. Show (webbrowser1.document. Window. Frames ["Main"]. Document. Body. innerhtml );

2. Obtain the htmldocument interface of the frame.

Htmldocument Doc = (htmldocument) webbrowser1.document. domdocument;
Object J;
For (INT I = 0; I <Doc. parentwindow. frames. length; I ++)
{
J = I;
Htmlwindow2class frame = Doc. parentwindow. frames. Item (ref J) as htmlwindow2class;
If (frame. Name = "Main ")
{
Messagebox.show(frame.doc ument. Title );
}
}

3. Obtain the ihtmldocument2 interface of the frame.

Ihtmldocument2 Doc = (ihtmldocument2) webbrowser1.document. Window. Frames ["Main"]. Document. domdocument;

4. Get the clicked connection in the frame

Private void webbrowser1_navigating (Object sender, webbrowsernavigatingeventargs E)
{
String url = webbrowser1.document. Window. Frames ["Main"]. Document. activeelement. getattribute ("src ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.