views:

5918

answers:

6

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. The plugin could be missing and needs to get downloaded in this case. The dynamically added embed tag for Firefox works as expected. The dynamically added object tag for Internet Explorer seems to do nothing at all. The object tag needs the following attributes to function properly.

id ="SomeId" classid = "CLSID:{GUID}" codebase = "http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1"

Even a general working idea or method would be nice.

Thanks!

+6  A: 

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 = "<OBJECT id='foo' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'.....etc";

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: <body onload="loadAppropriatePlugin()">

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 <script> tag in your <head> section:

function getIEVersion() { // or something like this
   var ua = window.navigator.userAgent;
   var msie = ua.indexOf("MSIE ");
   return ((msie > 0) ? parseInt(ua.substring(msie+5, ua.indexOf(".", msie))) : 0);
}

function loadAppropriatePlugin() {
    if(getIEVersion() != 0) { // this means we are in IE
        document.getElementById("Foo").innerHTML = "<OBJECT id='foo' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'.....etc";
    } else {
        // if you want to maybe do the same for FF and load that stuff...
    }
}

Does that help?

Jason Bunting
First, thank you for the fast reply. I guess the problem is the real dynamic I need. It is only one page, with different sections in it. One of the sections requires the ActiveX when running in IE or the Plugin when running in Firefox. Therefore I have to inject the code after the page is loaded.
Detlef D. Doerscheln
I understand that, that is what this code can do for you.
Jason Bunting
OMG an empty DIV tag. Is that embarrassing or what? :-) Well, I am not a Web Developer so I ask funny questions and come up with funny solutions at time. Thank you very much!
Detlef D. Doerscheln
No problem, I didn't realize you marked this as the answer when I was adding all of that other stuff, so just ignore it. :)
Jason Bunting
A: 

Two ways.

1) Just do a document.write where ever you want it

<script type="text/javascript">
<!--
   document.write("<object id=\"SomeId\" classid=\"CLSID:{GUID}\" codebase=\"http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1\"&gt;&lt;/object&gt;");
-->
</script>

2) Edit a tag's innerHTML property.

<div id="my-div"></div>
<script type="text/javascript">
<!--
   document.getElementById("my-div").innerHTML = "<object id=\"SomeId\" classid=\"CLSID:{GUID}\" codebase=\"http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1\"&gt;&lt;/object&gt;";
-->
</script>

EDIT: Just a note, it is best to not use JavaScript to do this, since people with JavaScript enabled will never see the object. It would be better to just place it in your HTML.

Andrew G. Johnson
A: 

First, thank you all for the fast reply. I guess the problem is the real dynamic I need. It is only one page (per specification), with different sections in it. One of the sections requires the ActiveX when running in IE or the Plugin when running in Firefox. Therefore I have to inject the code after the page is loaded. The ActiveX or the Plugin should not get downloaded before the appropriate section of the page is visible. The user should also not get "scared" to see a download coming before s/he read the first sections of the page. As said only one page per client request.

Detlef D. Doerscheln
A: 

I guess I have to learn to be more specific if I ask a question. Not every Plugin which you can use must have something to do with Flash. In fact in this case it is a windowless plugin.

Detlef D. Doerscheln
A: 

Dear Jason Bunting,

I dont know what to say to express my appreciate to your answer since it is the only Google search result for this issue on the Net. My problem is exact as mentioned by Detlef D. Doerscheln. My problem is to load PDF content dynamically via Jquery and works in FF, didn't work in IE. I apply your solution and it works. You save my life man !

Thanks a lot mate. Best wishes. Sam Nguyen.

A: 

var object = document.createelement('object')

object.setAttribute('id','name')

object.setAttribute('clssid','CLSID:{}')

n like this ...< PARAMS >

the above snippet written on the fly !!!

google chrome awsome dev tool javascript console try it

Regards

dgFish3r