我有一个本地文件“empty.htm”(正文中只包含“I'm empty”),一个远程网页和两个WebBrowser控件。WebBrowser1导航到远程页面,WebBrowser2导航到本地文件。两者都适当地显示其内容。
string rootIDToCopy = "InterestingDivID";
HtmlDocument htmlDocument = webBrowser1.Document;
HtmlElement rootElementToCopy =
htmlDocument.GetElementById(rootIDToCopy);
if (rootElementToCopy != null)
{
HtmlDocument dest = webBrowser2.Document;
if (dest != null)
{
HtmlElement destBody = dest.Body; // Point 1
destBody.AppendChild(rootElementToCopy); // Point 2
}
}
现在,当我在第1点时,我看到destBody存在,没有子对象,并且有一个“I'm empty”的InnerHTML。rootElementToCopy看起来有效(有三个子项和一个ok InnerHtml)。但是,在第2点,我得到“值未在预期范围内失败”(可能来自Windows.Forms.unsafentivemethods.IHTMLElement2.InsertAdjacentElement)。
谢谢你的帮助!