【问题标题】:JQuery removed background from iframeJQuery 从 iframe 中删除背景
【发布时间】:2010-03-22 13:08:19
【问题描述】:

我正在尝试删除通过 iframe 在灯箱效果中加载的页面上的背景图像。我已经验证 body 是被选中的 iframe 中的正确元素,但我无法让背景图像消失。我错过了什么明显的东西吗?

var body = jQuery('#fancybox-frame').contents().find('body');

body.css({
 'background': 'none',
 'background-image': 'none',
 'background-color': '#fff'
});

更新:目前我的这个元素的 CSS 读取(根据萤火虫)...

body {
   background-color:#5A7E92;
   background-image:url("/images/background.gif");
   border:10px solid #021E2F;
   font-family:verdana,san-serif;
   font-size:10pt;
   margin:auto;
}

更新:您可以通过单击“邮件”链接在此处查看示例...... http://www.retailcustomerexperience.com/article/21532/GlobalShop-DOOH-measurement-essential-for-reaching-customers

【问题讨论】:

  • 框架页面是否与父页面在同一个域中?
  • 是的,他们在同一个域中。
  • 只是为了仔细检查,你确定你是在 iframe 加载后调用这个 javascript 吗?
  • 是的,它正在被调用,console.log(body) 确认了这一点。
  • 我访问了链接;您的代码已经正常工作了。

标签: jquery iframe


【解决方案1】:

背景可能在其他元素上。

在 Firebug 中检查 <iframe> 中的页面并检查哪个元素具有背景。

【讨论】:

  • 确认,在body元素上。
【解决方案2】:

我认为,如果您让值为空,它实际上不会达到您的预期。尝试将背景设置为“继承”并查看它的作用。

【讨论】:

    【解决方案3】:

    尝试将background-image 更改为none。这是该 css 属性的有效值,我相信这会显式删除您的背景图像。

    【讨论】:

      【解决方案4】:

      这可能不是完整的答案,但这可能会帮助您找到答案。

      <iframe frameborder="0" style="width:756px;height:439px;background-image:none;background-color:transparent" src="http://janemonheitonline.com/photos?KeepThis=true&amp;" hspace="0" allowtransparency="true"> </iframe>
      

      Internet Explorer 需要“allowtransparency”才能删除 iframe 上的背景图像和背景颜色。试试这段代码,看看背景图片是否在 iframe 上而不是 body 上。

      您可以在http://janemonheitonline.com 看到代码是如何工作的 通过单击任何主要导航链接。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-10
        • 2015-01-29
        • 2016-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多