How to Determine iFrame Load or Content Presence
Problem:
You seek a method to ascertain if an iFrame has successfully loaded or contains content, as standard approaches may not suffice. Determining the loaded state is crucial to triggering specific actions or handling scenarios where loading takes excessive time.
Solution:
To effectively address this issue, consider the following approach:
<script><br>function checkIframeLoaded() {</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">// Obtain the iFrame element var iframe = document.getElementById('i_frame'); var iframeDoc = iframe.contentDocument || iframe.contentWindow.document; // Evaluate loading status if ( iframeDoc.readyState == 'complete' ) { // Loading is completed; execute desired functionality afterLoading(); return; } // Loading is incomplete; re-check in 100 milliseconds window.setTimeout(checkIframeLoaded, 100);
}
function afterLoading(){
alert("I am here");
}
This script operates as follows:
The above is the detailed content of How to Determine if an iFrame Has Loaded and Contains Content?. For more information, please follow other related articles on the PHP Chinese website!