views:

596

answers:

4

I have created a facebook fan page here:

http://www.facebook.com/apps/application.php?id=120196931351044&v=app_120196931351044

It incorporates iframes to call certain pages/image galleries which use jquery. Everything works fine in all browsers except for Chrome. Nothing shows up in Chrome from the iframes, just empty white background.

I tried using load event instead of ready handler but still no luck.
Has anyone witnessed the similar issue in chrome?

Your help will be greatly appreciated.

The big images in the header come through iframe,a page incorporating jquery.

Update:

As shown in the comments below, it doesn't seem to work even in Safari as well.

Update 2

The same code seems to work in chrome when run outside of the iframe, here is the link to working page:

http://jsbin.com/esame4/4

Update 3:

It seems that this problem persists in chrome when using iframes as can be seen here:

http://www.google.am/support/forum/p/Chrome/thread?tid=2c81c3e3fd99b388&hl=en
http://forums.sharethis.com/topic.php?id=2742

A: 

A few suggestions, mostly related to your Javascript setup on the gallery.php page:

My first instinct is to say it's a bug (or even an intended response) in the way Chrome/WebKit handles cross-site scripting and other similar potential security holes. I know some security holes involve running script from inside an iframe (as this former Chrome bug refers to).

Perhaps it's something to do with you referencing your jquery.min.js from ajax.googleapis.com instead of hosting it on the same domain as your gallery.php page. Try putting a copy of jquery.min.js on your server and linking to that and see if it helps.

Also, try moving your the jQuery library <link> tag to inside your <head> tag, as that's a more appropriate place for it.

You might also try using the jQuery Innerfade library to run your rotating banner. It would clean up your script and, who knows, perhaps convince the browser that you're not trying to exploit a hole in security.

If you're unable to switch to using Innerfade, at least change your JavaScript variables to not be named with a $ (e.g. change your "$curbox" variable to "curbox"). It might further clear up any confusion the browser may be having with your Javascript. At the very least, it's good practice, especially when using jQuery.

JoshMock
@JoshMock: I tried all that you said, but still with no outcome :(
Sarfraz
You sure? Still looks like you are using $ in your variable names. I doubt it'll make a difference, but it's good practice anyway. http://www.codelifter.com/main/tips/tip_020.shtml
JoshMock
@JoshMock: Yeah, i had tried even replacing $ with jQuery but that isn't problem also.
Sarfraz
I mean in your actual variable names. Technically, you shouldn't have any special characters except for underscores in your variable names, but you have variables named "$curbox" and "$prevbox" when dollar signs aren't allowed in variable names. PHP is the only web language, to my knowledge, that requires or even allows that.Like I said, I doubt that'll fix the problem, but you should clean it up anyway.
JoshMock
A: 

Check the response headers in the page that you're trying to put into the iframe. You're looking for a header called x-frame-options.

This is a new security option that tells the browser not to load the frame content. Lots of web servers will add it by default.

It's something worth checking.

Keith
@Keith: Tried setting those headers with `header("x-frame-Options: SAMEORIGIN");` but still the problem persists.
Sarfraz
@sAc - so was there an _x-frame-options_ already set? If so changing it to SAMEORIGIN would help but only if your frame is a local page. Otherwise never mind - it was worth checking, just in case.
Keith
+1  A: 

Hey sAc, I've tryed it on Chrome 5.0.375.86 and it worked. Since safari and chrome uses the same web engine (webkit) it could inherit the same problem. Since it's a javascript problem, and now chrome uses google V8 javascript engine instead JavaScriptCore (default javascript engine from webkit), this problem seems to be solved in Chrome's last versions. Maybe it can be a problem on JavaScriptCore do not dispatching the ready or load events since DOM is already loaded on the document before the iframe has been constructed. A temporary solution could be set a flag to check if the content was initialized. Put a five to ten secs timer with setTimeOut to check this flag. If it not initialized, then call it on the setTimeOut callback. So if safari doesn't call the load or ready events, the setTimeOut could do it for you. Of course, don't put it inside your jquery layer. Put it as a pure javascript tag inside your HTML to be loaded by the iFrame.

Cheapshot
+2  A: 

If it's a problem with document.ready not getting called in the iframe because the page has already been loaded at that point, is it possible to instead put the javascript that you want to load at the bottom of the new page instead of in document.ready, so that it'll load up once everything else has been loaded? I've done something similar on some pages, like put a bit of javascript at the top of the page to show a loading image, and another chunk at the bottom to hide it, etc...

<html>
    <head><script>function pop(){alert("Page Loaded");}</script></head>
    <body>Lorum ipsum...</body>
    <script>pop();</script>
</html>
AndyD273