开发者

Iframe on Blogger javascript not working

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 pa开发者_运维问答ge</title>
</head>
<body>
<iframe src="fb.htm" runat="server" id="iframe1" width="500" height="500"></iframe>

</body>
</html>


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(&#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/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜