在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