How can I dynamically add an <object> tag with JavaScript in IE?

前端 未结 3 849
不知归路
不知归路 2020-12-16 08:16

I have to add either an embed tag for Firefox or an object tag for Internet Explorer with JavaScript to address the appropriate ActiveX / Plugin depending on the browser. Th

3条回答
  •  Happy的楠姐
    2020-12-16 08:40

    I needed to do this same thing and simply place all of the HTML needed for the OBJECT tag in a string in JavaScript and simply replace the innerHTML of a div tag with the OBJECT HTML and it works in IE just fine.

    // something akin to this:
    document.getElementById(myDivId).innerHTML = "
    
    

    That should work, it does just fine for me - I use it to embed Windows Media Player in a page.


    UPDATE: You would run the above code after the page loads via an event handler that either runs on the page's load event or maybe in response to a user's click. The only thing you need to do is have an empty DIV tag or some other type of tag that would allow us to inject the HTML code via that element's innerHTML property.


    UPDATE: Apparently you need more help than I thought you needed? Maybe this will help:

    Have your BODY tag look like this:

    Have somewhere in your page, where you want this thing to load, an empty DIV tag with an id attribute of something like "Foo" or whatever.

    Have code like this in a

    提交回复
    热议问题