WebBrowser.Document 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
HtmlDocument 현재 컨트롤에 표시되는 웹 페이지를 나타내는 항목을 WebBrowser 가져옵니다.
public:
property System::Windows::Forms::HtmlDocument ^ Document { System::Windows::Forms::HtmlDocument ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HtmlDocument Document { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HtmlDocument? Document { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Document : System.Windows.Forms.HtmlDocument
Public ReadOnly Property Document As HtmlDocument
속성 값
HtmlDocument 현재 페이지를 나타내거나 null 로드된 페이지가 없는 경우
- 특성
예외
이 WebBrowser 인스턴스는 더 이상 유효하지 않습니다.
인터페이스 구현에 대한 참조를 IWebBrowser2 기본 ActiveX WebBrowser 컨트롤에서 검색할 수 없습니다.
예제
다음 코드 예제에서는 웹 페이지 양식이 채워졌는지 여부를 확인 하려면 이벤트에 대 한 Navigating 처리기에서 속성을 사용 Document 하는 방법을 보여 줍니다. 입력 필드에 값이 없으면 탐색이 취소됩니다.
이 예제에서는 양식에 라는 webBrowser1컨트롤이 WebBrowser 포함되어야 합니다.
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText =
"<html><body>Please enter your name:<br/>" +
"<input type='text' name='userName'/><br/>" +
"<a href='http://www.microsoft.com'>continue</a>" +
"</body></html>";
webBrowser1.Navigating +=
new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
if (document != null && document.All["userName"] != null &&
String.IsNullOrEmpty(
document.All["userName"].GetAttribute("value")))
{
e.Cancel = true;
System.Windows.Forms.MessageBox.Show(
"You must enter your name before you can navigate to " +
e.Url.ToString());
}
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles Me.Load
webBrowser1.DocumentText = _
"<html><body>Please enter your name:<br/>" & _
"<input type='text' name='userName'/><br/>" & _
"<a href='http://www.microsoft.com'>continue</a>" & _
"</body></html>"
End Sub
Private Sub webBrowser1_Navigating( _
ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _
Handles webBrowser1.Navigating
Dim document As System.Windows.Forms.HtmlDocument = _
webBrowser1.Document
If document IsNot Nothing And _
document.All("userName") IsNot Nothing And _
String.IsNullOrEmpty( _
document.All("userName").GetAttribute("value")) Then
e.Cancel = True
MsgBox("You must enter your name before you can navigate to " & _
e.Url.ToString())
End If
End Sub
설명
HTML DOM(문서 개체 모델)을 통해 컨트롤에 표시되는 웹 페이지의 콘텐츠에 WebBrowser 액세스하려는 경우 이 속성을 사용합니다. 예를 들어 Windows Forms 애플리케이션에서 웹 기반 컨트롤을 사용하려는 경우에 유용합니다.
이 속성을 속성과 함께 ObjectForScripting 사용하여 컨트롤에 표시된 웹 페이지와 애플리케이션 간의 양방향 통신을 WebBrowser 구현할 수 있습니다. 이 메서드를 HtmlDocument.InvokeScript 사용하여 클라이언트 애플리케이션 코드에서 웹 페이지에 구현된 스크립트 메서드를 호출합니다. 스크립팅 코드는 호스트 액세스를 위해 제공되는 기본 제공 DOM 개체이며 속성에 대해 지정한 개체에 매핑되는 개체를 통해 window.external 애플리케이션에 ObjectForScripting 액세스할 수 있습니다.
웹 페이지의 내용에 문자열로 액세스하려면 속성을 사용합니다 DocumentText . 웹 페이지의 콘텐츠에 액세스 Stream하려면 속성을 사용합니다 DocumentStream .