admin管理员组文章数量:1122832
I have added an iframe to my website. Within the I-Frame is an area which is not required and I would like to hide.
I have tried to inject CSS into the i-frame using
Functions.php
add_action( 'wp_enqueue_scripts', 'Eazy_scripts' );
function Eazy_scripts() {
wp_register_script('js-iframe', get_stylesheet_directory_uri() . '/js/iframe.js', array('jquery'),'1.1', true);
wp_enqueue_script('js-iframe');
}
The script iframe.js
jQuery(document).ready(function(){
jQuery("#EazyOpsFrame").on("load", function() {
let head = $("#EazyOpsFrame").contents().find("head");
let css = '<style>div.fixed.area{display:none !important}</style>';
jQuery(head).append(css);
});
});
This doesnt seem to work, are there any recommendations?
I have added an iframe to my website. Within the I-Frame is an area which is not required and I would like to hide.
I have tried to inject CSS into the i-frame using
Functions.php
add_action( 'wp_enqueue_scripts', 'Eazy_scripts' );
function Eazy_scripts() {
wp_register_script('js-iframe', get_stylesheet_directory_uri() . '/js/iframe.js', array('jquery'),'1.1', true);
wp_enqueue_script('js-iframe');
}
The script iframe.js
jQuery(document).ready(function(){
jQuery("#EazyOpsFrame").on("load", function() {
let head = $("#EazyOpsFrame").contents().find("head");
let css = '<style>div.fixed.area{display:none !important}</style>';
jQuery(head).append(css);
});
});
This doesnt seem to work, are there any recommendations?
Share Improve this question edited Jul 7, 2023 at 13:23 PaulMcF87 asked Jul 7, 2023 at 12:57 PaulMcF87PaulMcF87 1316 bronze badges 3 |1 Answer
Reset to default 0If the source of the iframe is not on the same domain as the page that the iframe is embedded on, you cannot change contents inside the iframe.
If the iframe's source is on the same domain, add the CSS directly to the source page.
More: https://stackoverflow.com/a/36513940
本文标签: jqueryInjecting CSS into Iframe
版权声明:本文标题:jquery - Injecting CSS into Iframe 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293522a1929164.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$("#EazyOpsFrame").contents().find( 'div.fixed.area' ).hide()
; – Howdy_McGee ♦ Commented Jul 7, 2023 at 14:20<style>div.fixed.area{display:none !important}</style>
change to<style>display:none !important</style>
– PaulMcF87 Commented Jul 7, 2023 at 14:42