Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross domain iframe content load detection

I have a rather interesting problem. I have a parent page that will create a modal jquery dialog with an iframe contained within the dialog. The iframe will be populated with content from a 3rd party domain. My issue is that I need to create some dialog level javascript that can detect if the content of the iframe loaded successfully and if it hasn't within a 5 second time frame, then to close the dialog and return the user to the parent page.

I have researched numerous solutions and only two are of any true value.

  1. Get the remote site to include a javascript line of document.domain = 'our-domain.com'.
  2. Use a URL Fragment hack, but again I would need the request that the remote site able to modify the URL by appending '#some_value' to the end of the URL and my dialog window would have to poll the URL until it either sees it or times out.

Are these honestly the only options I have to work with? Is there not a simpler way to just detect this?

I have been researching if there's a way to poll for http response errors, but this still remains confined to the same restrictions.

Any help would be immensely appreciated.

Thanks

like image 804
rik_davis Avatar asked May 02 '10 17:05

rik_davis


People also ask

Can I load an iframe from a different domain?

Generally, web application allows script running between pages(parent and iframe pages) in the same domain based on same-origin-policy. Unfortunately it does not support scripts if different domain. The policy does not allow it.

How do I find iframe cross-domain?

to select the iframe with querySelector . Then we define the canAccessIFrame function that checks if the iframe has the contentDocument property defined. If it's defined then it's not a cross-domain iframe or it's cross domain and cross domain is allowed. Otherwise, false is returned.

What is cross-domain iframes?

Learn about how cross-domain iframe can be used to safely circumvent browser restrictions on scripts that process code in a different domain. Applies to: Skype for Business 2015. Web applications that interact with UCWA 2.0 resources require a cross-domain iframe for all HTTP requests sent to UCWA 2.0.


1 Answers

The easiest way (if you can get code added to the external sites) is to have them add an invisible iframe pointing to a special html file on your domain. This could then use parent.parent.foo() to notify the original window about the load event.

Listening for the "load" event will only tell you if the window loaded, not what was loaded or if the document is ready for interaction.

like image 156
Sean Kinsey Avatar answered Oct 20 '22 01:10

Sean Kinsey