跨浏览器HTML5 iFrame

时间:2010-09-13 17:21:26

标签: jquery dom html5 cross-browser

现在我有一个iFrame对象,其无缝属性看起来很完美,

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.google.com%2F&amp;layout=standard&amp;show_faces=false&amp;width=400&amp;action=like&amp;colorscheme=light&amp;height=35" seamless></iframe>

带有几个css属性

iframe {
  overflow: hidden !important;
  border: none !important;
  width: 400px;
  height: 35px;
  background-color: #cce0da;
  text-align: right;
  padding-left: 20px;
}

然后对于Internet Explorer我有一些应用了一些jQuery的回退属性

$(function() {
  $('iframe', '.ie')
    .attr('allowTransparency', 'true')
    .attr('frameBorder', '0')
    .attr('scrolling', 'no');
});

我最终得到的是IE中透明的iFrame,带有不必要的边框。

我的代码可能存在问题?也许我的frameBorder属性的DOM操作不会在document.ready?

之后呈现

3 个答案:

答案 0 :(得分:2)

尝试直接在标记中添加“frameborder”属性...

<iframe frameborder="0"

答案 1 :(得分:1)

请问我的英语,我在脚本js

中使用此代码

这在HEAD部分

<!--[if lt IE 9]>
 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
 <script src="myscrip"></script>
<![endif]-->

这是我的剧本

jQuery("iframe").each(function() {

  var copy = jQuery(this).clone();

  jQuery(copy).attr("frameborder", '0');
  jQuery(copy).attr("scrolling", 'no');

  jQuery(copy).replaceAll(this);

});

中的首选添加脚本
jQuery(document).ready(function ()

小问题是用

解决的小刷新
 iframe css=display:none
 add in my script function .show after replaceAll

答案 2 :(得分:0)

如果您希望文档在HTML5中验证,则可以使用原始方法。要使其在IE中工作,您需要做几件事。 9:

1)克隆iframe,设置属性,然后附加到容器。或者从头开始创建iframe元素。 IE之后不会让你设置属性。

2)删除原始的iframe。

    $('#facebook-like iframe').clone().attr({ 'frameBorder': '0', 'allowTransparency': 'true', 'scrolling': 'no' }).appendTo('#facebook-like');
    $('#facebook-like iframe').first().remove();