house9 / jquery-iframe-auto-height

jQuery plugin to set the height of an iframe to its contents height
https://github.com/house9/jquery-iframe-auto-height
453 stars 211 forks source link

jQuery load event loads sporadically in IE8 #8

Open Mmjavellana opened 13 years ago

Mmjavellana commented 13 years ago

I was using the code this plugin is based on and I noticed that it worked sporadically in IE8. It didn't throw any errors, it just never fired the load event. Google brought me to this plugin, so I gave it a whirl. Same thing. Executing the plugin with the debug parameter showed me that it was never getting to the load event. As a quick and dirty fix for the site I'm working on, I ended up adding $.browser.msie to the opera/webkit check (Line 72, if ($.browser.safari || $.browser.opera || $.browser.msie){).

house9 commented 13 years ago

I don't see this in your repo anymore, did you remove it? in most tests I have done it seemed to work with IE with out going through this code path? I am a bit hesitant to make that change

Mmjavellana commented 13 years ago

I never added this to my repo since it was, I feel, a pretty bad hack (unless it's the only way to fix it and then, well, it's still a bad hack). I just added it directly to the project I needed to use it in. I wasn't proposing it as a serious solution, just hoping to provide helpful information. Reading through my previous comment, I apparently left out a little bit of information that may help, so I'm going to reword the problem with that information.

The issue is that the load event was not firing, in IE8 only (maybe IE9, but I don't have that available for testing), for the iframes on specific pages within my site. It worked fine on all but two pages which are secure pages. The iframe content is also secure and includes the Comodo corner of trust logo. My only guess, and I don't see how this can even be the issue, is that the iframe is managing to load before the load event handler is added to to it.

If you are unable to reproduce this problem, I suppose it may be something unique in my project, but I don't know what that might be.

house9 commented 13 years ago

yeah, things do get finicky with iframes and the different possible content they contain

do you think something like a force delayed resize option would be helpful? false by default, but it could force all code execution down the $.browser.safari path if desired by the user of the library, just an idea

Mmjavellana commented 13 years ago

Is there a way in jQuery to check if an object is already loaded? I couldn't find anything, but if so, then the solution I wanted to use for my project goes like this:

  1. Bind the load event.
  2. Check if object is already loaded and therefore won't fire the load event.
  3. Fire the load event.

I couldn't figure out how to do #2, but if it is possible, this might allow you to get rid of the $.browser.safari path completely.

Mmjavellana commented 13 years ago

Oops, that wasn't supposed to be a link. :)

Mmjavellana commented 13 years ago

I checked the latest code in my project, and it's still having that same issue in IE8 without my aforementioned hack. Also, it turns out that it has nothing to do with secure pages, it's happening on normal pages as well. The load event is being bound, when the iframe changes it resizes as expected, the initial load just isn't firing.

house9 commented 13 years ago

would it be possible for you to send me the rendered html - parent page and the nested iframe?

Mmjavellana commented 13 years ago

I'll send you a message with a link to the page. If you still prefer the rendered html, let me know and I can do that too.

adamjgray commented 12 years ago

I'm actually seeing something similar in ie9 after I added the tag to the header. Or rather, I changed it from ie7 to edge. From what I'm seeing in the network capture, it looks like ie9 is aborting the request for the iframe contents (presumably because it already has them and they aren't expired yet?) I'm guessing that because of this abort, the load event isn't fired because it wasn't "loaded" it was just inlined. Adding ie to the browser check for browsers to kick in the nuts and force the iframe navigation seems to do the trick. A dirty hack to be sure, but that's better than my iframe not showing all the contents it needs to.

withremote commented 11 years ago

I just tested on browserstack.com and XP IE8 and lower doesn't expand the frame. Windows 7 IE8 does work though.

house9 commented 11 years ago

@withremote - can you create a gist with the markup/js code that doesn't work

withremote commented 11 years ago

https://gist.github.com/4693420 is the code not working in IE8 XP

house9 commented 11 years ago

is it being served up via webserver? i.e. localhost or other, could be browser security issue if served from the local file system

also - if you declare the iframe markup before the script, you don't need it wrapped in $(document).ready, it will resize when the iframe load event occurs; not sure if that will solve this issue?

withremote commented 11 years ago

Removing the $(document).ready fixed it apparently, thanks!

claudia1204 commented 10 years ago

it didn't resize height in ie9/8 when iframe's src was changed. solution :+1: ended up adding $.browser.msie to the opera/webkit check (Line 72, if ($.browser.safari || $.browser.opera || $.browser.msie){).(by first comment Mmjavellana,thanks! )