Home  >  Article  >  Web Front-end  >  How to Execute a Callback When an IFRAME Finishes Loading Across Domains Without Direct Content Access?

How to Execute a Callback When an IFRAME Finishes Loading Across Domains Without Direct Content Access?

DDD
DDDOriginal
2024-10-19 12:25:30217browse

How to Execute a Callback When an IFRAME Finishes Loading Across Domains Without Direct Content Access?

Cross-Domain IFRAME Loading Callback

You need to execute a callback when an IFRAME has finished loading, without direct access to the IFRAME content.

Solution with Timeout

As mentioned in the provided response, accessing the IFRAME body is possible if the URL is on the same domain. To address the issue of the callback not having data, try using a timeout to remove the IFRAME:

<code class="javascript">$('#myUniqueID').load(function () {
  if (typeof callback == 'function') {
    callback($('body', this.contentWindow.document).html());
  }
  setTimeout(function () {$('#frameId').remove();}, 50);
});</code>

This approach delays the removal of the IFRAME, allowing the callback to retrieve data before the element is destroyed.

The above is the detailed content of How to Execute a Callback When an IFRAME Finishes Loading Across Domains Without Direct Content Access?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn