0

So, I'm trying to make it so that when an element (inside the iframe) becomes hidden (display: none), it would make the iframe have display none.

I've tried:

var iframe = $('.preloader').contents().find('*');

if((iframe).is(':hidden')) {
  $('.preloader').css('display','none');
}

and

if($('.preloader').contents().find('*').is(':hidden')) {
  $('.preloader').css('display','none');
}

These both do not work.

HTML

<iframe class="preloader" src="https://sorrycantsay.net/preloader"></iframe>

This may help:

Detect if an element is visible

Selecting an element in iFrame jQuery

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Tigerrrrr
  • 526
  • 6
  • 24

1 Answers1

1

The easiest way for me when working with iframes is using the postMessage method + the onmessage event. It enables easy communication between iframe and parent. Additional examples here: https://javascript.info/cross-window-communication#postmessage

julifos
  • 142
  • 1
  • 2
  • 10
  • Can I have an example of how this would be done? I need to check if an element in the iframe is hidden, if so, make the iframe display as none – Tigerrrrr Mar 19 '19 at 16:05