0

我的 iframe 包含一些应该在正文加载时触发的 javascript,而 iframe 在嵌入纯 HTML 页面时可以正常工作,当集成到博客 HTML/javascript 小部件中时,iframe 中的 javascript 不起作用..建议。仅在 Firefox bc 中尝试过病毒和工具栏吃过IE?

iframe 页面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title> 
     <script language="javascript" type="text/javascript">
       function change() {
           var text = "someaddress";
           window.location = "http://something.com/fb2.aspx" + "?url=" + text;
       }
   </script>
</head>
<body bgcolor="#333333" onload="change()">
</body>
</html>

Blogger 博客上的 HTML/javascript 小部件的代码

<iframe scrolling="no" src="http://something.com/fb.htm" width="200" height="70" 
frameborder="0" name="myInlineFrame"></iframe>

嵌入在这个纯 HTML 页面中的 sam iframe 会按应有的方式执行 javascript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Stats page</title>
</head>
<body>
<iframe src="fb.htm" runat="server" id="iframe1" width="500" height="500"></iframe>

</body>
</html>
4

1 回答 1

1

在幕后,Blogger Widget/Gadget 系统似乎正在使用一种将代码添加到 DOM 的方法,该方法阻止了任何 JavaScript 的执行。通常,如果通过将内容附加到 .innerHTML 对象来添加内容,就会发生这种情况。DOM 元素被渲染,但任何包含的 JavaScript 都不会执行。

解决此问题的方法不在此问题的范围内,因为这是博客问题。

您的解决方案是直接编辑 Blogger 模板,然后将 IFRAME 粘贴到您希望它出现在模板本身中的位置。换句话说,不要使用小部件。

下面是我自己的 Blogger 模板的一部分,在结束正文元素之前有一个 iframe:

   </div>
  </div>
 </div>

 <script type='text/javascript'>
  window.setTimeout(function() {
     document.body.className = document.body.className.replace(&#39;loading&#39;, &#39;&#39;);
   }, 10);
  </script>

  <!-- Iframe in template -->
  <iframe scrolling="no" src="http://somedomain.com/fb.htm" width="200" height="70" 
     frameborder="0" name="myInlineFrame"></iframe>
  <!-- Iframe in template -->

</body>

  <macro:includable id='sections' var='col'>
   <macro:if cond='data:col.num == 0'>
   <macro:else/>
于 2011-01-06T01:31:21.360 回答