我必须为Firefox添加embed标记或使用JavaScript添加Internet Explorer的对象标记,以根据浏览器寻址相应的ActiveX /插件。插件可能会丢失,在这种情况下需要下载。动态添加的Firefox嵌入标记按预期工作。 Internet Explorer的动态添加对象标记似乎什么都不做。 object标签需要以下属性才能正常运行。

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

即使是一般的工作理念或方法也不错。

谢谢!

有帮助吗?

解决方案

我需要做同样的事情,只需将OBJECT标签所需的所有HTML放在JavaScript中的字符串中,然后用OBJECT HTML替换div标签的innerHTML,它就可以在IE中运行了。

// something akin to this:
document.getElementById(myDivId).innerHTML = "<OBJECT id='foo' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'.....etc";

这应该可行,它对我来说没问题 - 我用它在页面中嵌入Windows Media Player。


更新:您可以在页面加载后通过在页面的加载事件上运行的事件处理程序运行上面的代码,也可以响应用户的单击。你唯一需要做的就是有一个空的DIV标签或其他类型的标签,它们允许我们通过该元素的 innerHTML 属性注入HTML代码。


更新:显然你需要比我想象的更多的帮助吗?也许这会有所帮助:

让您的BODY标记看起来像这样:&lt; body onload =&quot; loadAppropriatePlugin()&quot;&gt;

在你的页面中的某个地方,你想要加载这个东西,一个空的DIV标签,其 id 属性类似于“Foo”。或者其他什么。

&lt; head&gt; 部分的&lt; script&gt; 标记中包含这样的代码:

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...
    }
}

这有帮助吗?

其他提示

var object = document.createelement('object')
object.setAttribute('id','name')
object.setAttribute('clssid','CLSID:{}')

其他参数也一样。

两种方式。

1)只需在任何你想要的地方做一个document.write

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

2)编辑标签的innerHTML属性。

<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\"></object>";
-->
</script>

编辑:只需注意,最好不要使用JavaScript来执行此操作,因为启用了JavaScript的人永远不会看到该对象。最好将它放在HTML中。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top