在Webbrowser
控件中有一个网页(文档)。我知道如何将任何HTML元素插入到正文中。在Webbrowser的文档中插入HTML对象元素
问题是,我该如何插入<object>
及其<param>
?我必须保留现有的文件,所以我不会使用Webbrowser1.Document.Write()
。
Dim player As HtmlElement = Webbrowser1.Document.CreateElement("object")
player.SetAttribute("width", "640")
player.SetAttribute("height", "480")
Dim param As HtmlElement = Webbrowser1.Document.CreateElement("param")
param.SetAttribute("name", "movie")
param.SetAttribute("value", "http://foo.bar.com/player.swf")
player.AppendChild(param) '<== throws an exception
Webbrowser1.Document.Body.AppendChild(player)
抛出的异常:“值不是一组有效的查找值中”(我猜,因为我使用VS2010的法语版本,这给了我“香格里拉valeur n'est PAS包括丹斯拉谱斑attendue。”)
替代方法
终于可以追加使用Navigate()
方法使用Javascript URI的<object>
元件。这有点难看,但它有效。
抛出的异常堆栈跟踪包含'InsertAdjacentElement'方法,所以我认为它在内部使用。无论如何,直接使用它会引发相同的异常。我没有在.NET 4中找到'ApplyElement'方法,'InnerHTML'属性抛出另一个异常。 – Velcro