2

I'm trying to inject some CSS into an iFrame, and it works fine, except there is a delay before the new CSS takes effect. How can I set priority for iframe CSS? I use this code for the iframe section:

<iframe id="myiFrame" fetchpriority="low" loading="lazy" width="1024px" height="200px" src="mypage.html"></iframe>

And use this code for styling:

<script>
window.onload = function() {
  let frameElement = document.getElementById("myiFrame");
  let doc = frameElement.contentDocument;
  doc.body.innerHTML = doc.body.innerHTML + '<style>.jeg_header_wrapper{display:none!important}</style>';
}
</script>
  • The delay could be caused by the `window.onload`, as it waits for everything to be loaded. `document.onload` should be faster, as stated in this answer https://stackoverflow.com/a/588048/8783818 – Nicola Spadari Jul 15 '22 at 11:30

0 Answers0