Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1974
  • Last Modified:

Fancybox: Closing IFrame FancyBox loaded from another domain

I am able to successfully close an IFrame fancybox on the same domain using a hyperlink in the IFrame document, but not when it is called from another domain.  This appears related to security settings, at least in IE 9.

  + FancyBox
     IFrame > remote.domain.com
     Click: parent.$.fn.fancybox.close();

SCRIPT5: Access is denied.

Is there a way to trust the remote domain so that I am able to add close buttons to augment than the standard circle X in the top right corner?
  • 2
  • 2
1 Solution
David S.Commented:
No. The only way to do that would be to use a proxy script, run under your domain.
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
Your one option is using the change in fragment -hash- of main page url and make main page react to that change as you programmed before (closing fancybox in this case)

something like ;
// in iframe ;

Open in new window

and in main page you need to give ability to watch hashchanges
add these
if ("onhashchange" in window) { // event supported?
    window.onhashchange = function () {
else { // event not supported:
    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            storedHash = window.location.hash;
    }, 100);

function hashChanged(storedHash){
if(storedHash =="close_fancybox") $.fancybox.close()

Open in new window

look at this fiddle


you will just remove fancybox opener and change
 <a onclick="location+='#close_fancybox';return false;"
 <a onclick="parent.location+='#close_fancybox';return false;"
OfficedoxsAuthor Commented:
Thank you for your time and efforts here.

I could be wrong, but this looks like it only works for an inline.  I am accessing an IFrame for a remote domain which Kravimir illudes to has the underlying cross-domain security wrinkles.

I'm trying to overlay dynamic content from Site 2 on top of Site 1 with minor interaction between each other, such as closing the window.  I think I'm locked out on that account.
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
No this works with both inline and iframe. I cannot show you iframed version because i don't have chance  to change your files. If you cannot figure this out send both main and iframe html sources .Then i can show you the changes you need to do.
OfficedoxsAuthor Commented:
Apologies for the delay, works great!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now