【问题标题】:How to applying css style into an iframe content? [duplicate]如何将 css 样式应用到 iframe 内容中? [复制]
【发布时间】:2013-03-26 15:07:12
【问题描述】:

我正在尝试为 iframe 中的内容应用 CSS 样式,请查看此链接 http://jsfiddle.net/pPqGe/

jQuery:

$(document).ready(function() {
    $('iframe').contents().find('h1').css('color','red');
});

HTML:

<iframe src="mysite" width="100%" height="100%" id="myframe"></iframe>

对于 iframe 源,我使用了一个实时网站。

【问题讨论】:

  • 您可以将它们作为查询字符串传递给 iframed 页面。
  • shnisaka 是对的,否则是不可能的。出于安全原因,浏览器带有该限制,称为“跨域脚本”。
  • 如果您正在调用位于同一域中的另一个网页,则只需使用 ajax 调用该页面内容。

标签: html css iframe


【解决方案1】:

它有效。问题是没有H1,只有H2。 查看此链接http://jsfiddle.net/pPqGe/1545/

HTML:

<iframe src='jsfiddle.net'></iframe>

JavaScript:

$(document).ready(function() {
    $('iframe').contents().find('h2').css('color','red');
    $('iframe').contents().find('#header').css('opacity','.2');
});

【讨论】:

  • 是的,你是对的。它在 jsfiddle 中运行良好,但我正在为 iframe 使用另一个源文件。 例如:" " 不支持。。标题类在smasingmagazine上可用,但不受影响。
猜你喜欢
  • 2019-06-04
  • 2013-05-15
  • 1970-01-01
  • 2013-01-15
  • 2017-04-07
  • 2014-01-28
  • 1970-01-01
  • 1970-01-01
  • 2011-04-12
相关资源
最近更新 更多