Home > Web Front-end > JS Tutorial > 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
Release: 2024-10-19 12:25:30
Original
309 people have browsed it

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>
Copy after login

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!

source:php
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template