简体   繁体   中英

How to know if the iFrame has completed loading with javascript

I would like to know which callback to use when the iframe has completed loading.


const iFrame = window.parent.document.getElementById('ReviewGeologueFrame'); 

iFrame.src = `/Review/GeologueFrame?id=${str}`;

iFrame.onreadystatechange = function (){

            if (iFrame.readyState !== 'loading')
            {
                console.log('iFrame has completed loading');

            }


}

When i tried the above snippet, there is no message in the console; what am doing wrong

You could always try using some jquery.

$('iframe').on('load', function () {
console.log('iFrame has completed loading'); });

This works for me. You might also want to look here . It is another Stackoverflow page where they discuss the same issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM