12

I have this:

<div class="upload_slide">
    <iframe class="upload_iframe" style="visibility:hidden;"></iframe>
</div>

If I then post some files to the iFrame and set .upload_slide to display:none;, while it's loading, will this affect the loading of the iFrame or the detection of when it finished loading?

ShadowStorm
  • 813
  • 4
  • 10
  • 23

5 Answers5

11

No, the iFrame's loading and load detection should not be compromised by setting the display to none.

CSS is just for style, it has no ability to affect the DOM.

TheCarver
  • 18,072
  • 24
  • 91
  • 146
  • 31
    Setting `display:none` on an `` (or any of its parents) will prevent it from loading. CSS *can* affect the DOM, but alas, not for ` – Steven Vachon Jul 17 '14 at 21:20
  • That isn't true. Images will load regardless of visibility, unless you're using `loading="lazy"`. CSS background images however, _do_ react to visibility, although the behaviour isn't totally standard across browsers. – JaffaTheCake Mar 12 '20 at 08:56
  • I actually came here because I've found out that setting 'display: none' on an iframe in chrome reload its url. – Hagai Wild May 07 '20 at 18:49
10

There shouldn't be a problem but if there is, a good trick can be to move the element offscreen rather than hiding it. You can create a class like

.offscreen{
    position: absolute;
    left: -5000px;
}

which you can add and remove as needed.

robC
  • 2,342
  • 1
  • 17
  • 27
9

Firefox currently does have an issue with display:none:

Some browsers assume that when "display:none" is applied to replaced elements (like Flash or an iframe) the visual info for that element is no longer needed. So, if the element is later displayed by the CSS, the browser will actually recreate the visual data form scratch.

I imagine that having the iframe default to "display:none;" makes the browser skip the rendering of the HTML so the tags don't have any dimensions. I would set the visibility to "hidden" or position it off the page rather than use "display:none;".

Steven Paligo

Link

Community
  • 1
  • 1
Ricardinho
  • 1,049
  • 11
  • 14
  • i guess this is happening in iframes with chrome 59. Some table border dashed style is not loaded, if the iframe is set do display:none, and you do print of the iframe. – Miguel Jul 07 '17 at 14:48
1

Nope.. Not at all..

CSS - display:none or visibility:hidden only says the browser to not to show the iframe content to user.

But the functionality will work fine without any issues.

balanv
  • 10,150
  • 25
  • 88
  • 134
0

As far as I am aware, it should work fine. I've been using hidden iframes to load stuff for a while and haven't had any issues.

That said I know that some browsers try to be efficient by not loading images that are hidden, so it's possible that some browsers (particularly mobile ones) do the same with iframes.

Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540