创建<样式>JavaScript 中的标签,然后访问 cssRules样式>
我真的希望这不是一个愚蠢的问题......在过去的几个小时里我一直在用头撞墙试图解决它。
这本质上是 How to create a
谁能解释一下如何为 iframe 创建样式表,以便在 Chrome 和 Safari 中为我提供“cssRules”属性?
我的目的是将样式表添加到我在网页中创建的 iframe 中,因为它似乎没有附带样式表。后来,我希望将一些样式从封闭文档的样式表复制到 iframe 的样式表,但我还没有做到这一点。一旦我解决了上述问题,如果有人知道这样做的任何警告,我会提前感激不尽。
I really hope this isn't a stupid question...I've been beating my head against the wall for the last few hours trying to solve it.
This is essentially a followup question to How to create a <style> tag with Javascript, elsewhere on Stack Overflow. The techniques described by Tom and Michael work great in IE, Firefox, and Opera, and almost work in Chrome and Safari. The problem is, in Chrome and Safari, no "cssRules" property is created for the style sheet! The other browsers create a "cssRules" property (well, IE creates a "rules" property, but you knew that already).
Can anyone explain how to create a style sheet for an iframe that'll give me a "cssRules" property in Chrome and Safari?
My intention is to add a style sheet to an iframe that I created in my web page, since it doesn't seem to come with one. Later, I hope to copy some of the styles from the enclosing document's style sheet to the iframe's style sheet, but I haven't gotten there yet. If anyone knows of any caveats to doing that once I've solved the above problem, I'd be grateful in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经在 Firefox 3.6、Chromium 8、Opera 11 (ubuntu 10.10)
temp.html 中进行了测试:
index.html:
当我单击按钮时,iframe 中的背景变为红色。
PS如果重复的话抱歉。我现在才打开您帖子中指向另一个主题的链接
I've tested in Firefox 3.6, Chromium 8, Opera 11 (ubuntu 10.10)
temp.html:
index.html:
When I click the button, background in iframe becomes red.
P.S. Sorry if it is repeating. I've only now opened the link in your post to another topic