我有一个简单的页面,其中包含一些iframe部分(用于显示RSS链接)。如何将相同的CSS格式从主页应用到iframe中显示的页面
编辑:除非设置了适当的CORS标头,否则此操作不适用于跨域
这里有两种不同的东西:iframe块的样式和嵌入iframe的页面的样式。可以按常规方式设置iframe块的样式:
<;iframe name=“iframe1”id=“iframe1”src=”https://stackoverflow.com/questions/217776/empty.htm"
frameborder=“0”border=“0”cellspacing=“0”
style=“边框样式:无;宽度:100%;高度:120px;”</iframe>;
iframe中嵌入的页面样式必须通过将其包含在子页面中进行设置:
<;link type=“text/css”rel=“Stylesheet”href=”https://stackoverflow.com/questions/217776/Style/simple.css“/>;
也可以使用Javascript从父页面加载:
var cssLink=document.createElement(“链接”);
cssLink.href=”https://stackoverflow.com/questions/217776/style.css";
cssLink.rel=“样式表”;
cssLink.type=“text/css”;
frames['iframe1'].document.head.appendChild(cssLink);