Blogger javascript 上的 Iframe 无法正常工作

发布于 2024-10-10 17:31:32 字数 1427 浏览 6 评论 0原文

我有iframe可以在嵌入在平原HTML页面上的iframe时,可以在html页面上嵌入一些javaScript,而当集成在blogger html/javascript widget中时,iframe中的javascript在iframe中不起作用。病毒和工具栏吃掉了IE?

Blogger 博客上的 HTML/javascript 小部件的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>

代码

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

I have iframe that cointains some javascript that should fire on body load,while iframe works fine when embedded on plain HTML page,when integrated in blogger HTML/javascript widget,javascript in iframe don't work..suggestions.Tried only in Firefox bc viruses and toolbars eaten IE?

Iframe Page

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

Code of HTML/javascript widget on Blogger Blog

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

And sam iframe embedded in this plain HTML page executes javascript as it should

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮光沉寂 2024-10-17 17:31:32

在幕后,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('loading', '');
   }, 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/>

Behind the scenes, it appears that the Blogger Widget/Gadget system is using a method of adding code to the DOM that precludes the execution of any JavaScript. Oftentimes, this can happen if content is added by appending it to the .innerHTML object. The DOM element is rendered, but any included JavaScript does not execute.

A workaround for this is outside the scope of this question, because it's a blogger issue.

The solution for you is to edit the Blogger template directly, and paste your IFRAME where you would like it to appear in the template itself. In other words, don't use a widget.

Below is a portion of my own Blogger Template with an iframe right before the closing body element:

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

 <script type='text/javascript'>
  window.setTimeout(function() {
     document.body.className = document.body.className.replace('loading', '');
   }, 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/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文