user2638168
user2638168

Reputation: 1

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:

<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:

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)

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.

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.

Thanks for help...

Upvotes: 0

Views: 382

Answers (2)

taxilian
taxilian

Reputation: 14324

This is a pretty standard issue with npapi plugins, though; they don't behave reliably in any browser that I know of when you move them around in the DOM. Similar issues occur if you change the parent container to display: none, visibility: hidden, overflow: none, etc. ActiveX controls are even more fun.

The workaround I use is to put the plugin in a floating absolute positioned 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. It's a bit of a hack, but it works quite well.

Upvotes: 1

Georg Fritzsche
Georg Fritzsche

Reputation: 98974

If the plugin really is getting re-created you should file a bug - re-parenting shouldn't re-spawn the plugin per the WhatWG object element and being rendered sections.

Upvotes: 1

Related Questions