reload embedded swf in html page in IE

做~自己de王妃 提交于 2019-12-24 06:34:14

问题


I have a swf file embedded in a html page. I want to reload the swf file without refreshing the page.

There is a same problem asked here: reload/ reset embedded swf on click

And I tried the accepted answer and it works in chrome:

var obj = $("object#flash_99674493");
obj.html(obj.html());

But it seems it doesn't work in IE. How to make it work in IE?


回答1:


If your .swf is embedded with <object>, use data property:

document.getElementById('flash_99674493').data += '';

For ones embedded with <embed> use src:

document.getElementById('flash_99674493').src += '';

Adding the empty string to data or src causes their reload.

In IE we have to replace the object with the same one:

var o = document.getElementById('flash_99674493');
var n = o.cloneNode(!0);
o.parentNode.insertBefore(n, o);
o.parentNode.removeChild(o);



回答2:


Have you tried using regular JavaScript using a wrapper? I did a test with this working on old browser such as IE 9.

<!-- wrapper around your flash object -->
<div id="flash-content">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="200" height="200" id="SoundSpectrum2" align="middle">
            <param name="movie" value="SoundSpectrum2.swf" />
            <param name="quality" value="high" />
            ...

And then the JavaScript:

function reloadFlash() {
   var content = document.getElementById('flash-content');
   var currentArray = [];

   while (content.firstChild) {
      currentArray.push(content.firstChild.cloneNode(true));
      content.removeChild(content.firstChild);
   }

   currentArray.forEach(function(item) {
      content.appendChild(item)
   });
}


来源:https://stackoverflow.com/questions/44847484/reload-embedded-swf-in-html-page-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!