我将 iframe 用作一种灯箱容器,我需要在加载 url 后更改 iframe 内容的样式,但是我似乎无法使用 css 或jquery.
我试过:
iframe html body {text-align:center}
$('iframe html body').css('text-align','center');
而且似乎都没有任何效果,我也尝试设置其他属性,但它对内容根本没有影响。
这可以做到吗??
编辑
好的,这似乎是一个浏览器相关的问题,我实际上是在尝试根据加载的内容动态设置 iframe 的宽度和高度:
$('iframe').load(function () {
$(this).height($(this).contents().height());
$(this).width($(this).contents().width());
});
这在 safari 和 chrome 中有效,但在 Firefox 中完全无效!
最佳答案
如果 iframe 与父框架在同一个域中,您可以使用:
$("iframe").contents();
关于jquery - 更改加载的 iframe 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13656356/