简体   繁体   English

将网页中的npapi插件对象从一个div移动到另一个div,为什么插件会破坏并重新创建?[chrome,FireFox]

[英]move npapi plugin object in webpage from one div to another, why plugin destroy and recreate?[chrome, FireFox]

I got one plugin and embeded to my webpage page, the plugin is used to play media files(.mp3,mp4,m3u8, etc).my webpage looks like: 我有一个插件并嵌入到我的网页中,该插件用于播放媒体文件(.mp3,mp4,m3u8等)。我的网页看起来像:

<div id='div1'>Plugin</div>
<div id='div2'><div id='div2sub'></div></div>

Plugin created like 插件创建像

<object id='plugin' type='xxxx' width='xxxx' height='xxxx'></object>

the problem is: when i move plugin from div1 to div2sub like: 问题是:当我将插件从div1移动到div2sub时:

var x = document.getElementById('plugin');
var y = document.getElementById('div2sub');
y.appenChild(x);

then I find the result IE: the plugin still playing media file, video, audio output,it works fine(ActiveX plugin) Chrome and FireFox: No video, audio output,plugin not play media file anymore.(npapi Plugin) 然后我找到结果IE:插件仍在播放媒体文件,视频,音频输出,它工作正常(ActiveX插件)Chrome和FireFox:没有视频,音频输出,插件不再播放媒体文件。(npapi插件)

I found the reason is: with IE, the Plugin just moved,not destroy then recreate, with chrome and FireFox,the plugin was destroy then recreated, I have one function to register callback event on pluin, chrome console shows my plugin never received callback event, so media file can't be played. 我发现原因是:使用IE,插件只是移动,不破坏然后重新创建,使用chrome和FireFox,插件被销毁然后重新创建,我有一个函数在pluin上注册回调事件,chrome控制台显示我的插件从未收到回调事件,因此无法播放媒体文件。

My question is: Is there anyway I can do just move plugin, and the plugin will not be destroyed and recreated with chrome and FireFox, just works like with IE. 我的问题是:无论如何我只能移动插件,插件不会被破坏并使用chrome和FireFox重新创建,就像IE一样。

Thanks for help... 感谢帮助...

如果真的要重新创建插件,你应该提交一个错误 - 重新生成父母不应该根据WhatWG 对象元素正在渲染的部分重新生成插件。

This is a pretty standard issue with npapi plugins, though; 不过,这是npapi插件的一个非常标准的问题; they don't behave reliably in any browser that I know of when you move them around in the DOM. 当你在DOM中移动它们时,它们在我知道的任何浏览器中都不能可靠地运行。 Similar issues occur if you change the parent container to display: none, visibility: hidden, overflow: none, etc. ActiveX controls are even more fun. 如果将父容器更改为display,则会出现类似问题:none,visibility:hidden,overflow:none等.ActiveX控件更有趣。

The workaround I use is to put the plugin in a floating absolute positioned div. 我使用的解决方法是将插件放在浮动的绝对定位div中。 I put another div on the page where I want the plugin to be, and then whenever it needs to be moved I calculate the absolute position of the positioning div and move the floating div to be over it. 我在我想要插件的页面上放了另一个div,然后每当需要移动时,我计算定位div的绝对位置并将浮动div移到它上面。 It's a bit of a hack, but it works quite well. 这有点像黑客,但效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM