0

In the following example the flash in my HTML would not show after moving it's parent element in DOM. I use appendChild on enclosing div of my object element to move it somewhere else in the DOM hierarchy, but after the move is complete the containing flash would not show.

I get this error in IE 10 and firefox, in Chrome there seems to be no problem.

This error happened in much larger project, but I managed to distill it to the following little example.

<html>
<head>
<script>
  window.onload = function() {
     var copy = document.getElementById("s");
     document.getElementById("newparent").appendChild(copy); //if I comment out this line, example works
  }
</script>
</head>

<body>
  <div id="newparent"> <!-- here will the object be appended -->
  </div>
  <div id="s">
    <object width="50%" height="50%" data="http://www.w3schools.com/tags/helloworld.swf">SWF Not shown</object>
  </div>
</body>
</html>

If I comment out the second line of my onload function, the flash shows properly (but it is not moved around). I am not able to google anything. Perhaps I am not able to describe my problem, I am pretty new to HTML. Thanks in advice.


OK, so thanks to you guys, I had an idea of what to look for and I stumbled upon this article.

The problem I have seems to be that for some ?security? reasons the flash would not load after being moved. I devised this dirty workaround, simply I force browser to parse and recalculate the object tag. Is it so? I hope I understand well what am I doing.

<html>
<head>
<script>
  window.onload = function() {
     var copy = document.getElementById("s");
     document.getElementById("newparent").appendChild(copy);
     copy.innerHTML = copy.innerHTML; //dirty workaround
  }
</script>
</head>

<body>
  <div id="newparent"> <!-- here will the object be appended -->
  </div>
  <div id="s">
    <object width="50%" height="50%" data="http://www.w3schools.com/tags/helloworld.swf">SWF Not shown</object>
  </div>
</body>
</html>
4

1 回答 1

0

好的,多亏了你们,我知道要寻找什么,我偶然发现了这篇文章。

我遇到的问题似乎是一些?安全?移动后闪光灯无法加载的原因。我设计了这个肮脏recalculate的解决方法,只是强制浏览器解析和object标记。是这样吗?我希望我能很好地理解我在做什么。

<html>
<head>
<script>
  window.onload = function() {
     var copy = document.getElementById("s");
     document.getElementById("newparent").appendChild(copy);
     copy.innerHTML = copy.innerHTML; //dirty workaround
  }
</script>
</head>

<body>
  <div id="newparent"> <!-- here will the object be appended -->
  </div>
  <div id="s">
    <object width="50%" height="50%" data="http://www.w3schools.com/tags/helloworld.swf">SWF Not shown</object>
  </div>
</body>
</html>
于 2013-04-08T13:29:19.577 回答