开发者

Insert an HTML Object element in Webbrowser's document

In a Webbrowser control there is a webpage (the document). I know how to insert any HTML element into the body.

The problem is, how can I insert an <object> along with its <param>? I must keep the existing document, so I wouldn't use 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)

Thrown exception: "Value is not among the set of valid lookup values" (I guess, because I'm using french version of VS2010, which gives me "La valeur n'est pas comprise dans la plage attendue.")

WORKAROUND

Finally I could append an <object> element using Navigate() method with Javascript 开发者_如何学编程URI. It's a bit ugly, but it works.


Well, I realized my answer was exactly what you were doing. Oops.

The MSDN documentation shows a lot of methods for the object Object, but it doesn't specify appendChild. The appendChild method documentation specifies that it is a part of a bunch of objects, but not object. applyElement looks like it might work.

Also, the insertAdjacentHTML method and innerHTML parameter are valid on object Objects, and may be helpful.


Hrm - I'm not familiar with .net, but I have done something similar in Javascript. Chrome seems to produce the correct document setup with the following:

<script>
  var newObj=document.createElement( "object" );
    newObj.setAttribute( 'width', '640' );
    newObj.setAttribute( 'height', '480' );
    newObj.setAttribute( 'data', 'http://ozdoctorwebsite.com/test-4938161.gif' );

  var newParam=document.createElement( "param" );
    newParam.setAttribute( 'name', 'test' );

  newObj.appendChild( newParam );
  document.body.appendChild( newObj );
</script>

Basically - append your param element to the player and append the player to the document.body.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜