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

x
  • 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.

main.domain.com
  + 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?
0
Officedoxs
Asked:
Officedoxs
  • 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.
0
 
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 ;
parent.location+="#close_fancybox";

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 () {
        hashChanged(window.location.hash);
    }
}
else { // event not supported:
    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            storedHash = window.location.hash;
            hashChanged(storedHash);
        }
    }, 100);
}

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

Open in new window


look at this fiddle

http://jsfiddle.net/7T7E3/16/

you will just remove fancybox opener and change
 <a onclick="location+='#close_fancybox';return false;"
to
 <a onclick="parent.location+='#close_fancybox';return false;"
0
 
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.
0
 
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.
0
 
OfficedoxsAuthor Commented:
Apologies for the delay, works great!
0

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