简体   繁体   English

需要从父页面使用JavaScript将CSS样式添加到iframe

[英]Need to add css style to an iframe using javascript from parent page

Here is what I have so far: 这是我到目前为止的内容:

var head = $target.prop("iframe").toLowerCase().contents().find("head");
var css = '<style type="text/css">' +
          'MY CSS IS HERE' +
          '</style>';
jQuery(head).append(css);

Unfortunately, I have a couple issues: 不幸的是,我有几个问题:

1) I can't add jquery to the page via javascript (I tried but it's not working), so I need this converted to javascript. 1)我无法通过javascript将jquery添加到页面(我尝试过但无法正常工作),因此我需要将其转换为javascript。

2) I'm sure there is something wrong with the code. 2)我确定代码有问题。 Please help me fix the errors. 请帮助我修复错误。


NOTE: 注意:

I already tried everything here , but it does none of that is working especially because it's different than what I need (THERE IS NO ID OR CLASS NAME FOR THE IFRAME so everything on that question is irrelevant). 我已经在这里尝试了所有方法,但是它没有任何作用,特别是因为它与我所需要的有所不同(因为该IFRAME没有ID或类名,因此该问题上的所有内容均无关紧要)。

我认为,如果您在同一域下拥有iframe页面,可以尝试以下操作:

$("iframe").contents().find('head').append('<style type="text/css">' +'MY CSS IS HERE' + '</style>')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM