开发者

From inside an iframe, how can I determine if the parent page has finished loading?

Are there any properties or eve开发者_运维知识库nts I can listen for from within the iframe to determine this?

The iframe src and parent page are on different domains.


Only if you can modify the parent page as well. If you can't, it's XSS and there's no legitimate way to do it.

parent.html:

...
<body onload="theFrame.parentLoaded()">
...
<iframe src="http://other.domain.com/frame.html" name="theFrame"></iframe>
...

frame.html:*

...
<script type="text/javascript" language="javascript">
function parentLoaded(){
    //code here will be executed when the parent page has finished loading
}
</script>
...


I know you don't have control over the parent page, but if you can convince the host to add some code, you may be able to do something like the following:

//OnParent Page
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script>
    var bReady = false;
    $(document).ready(function () {
        bReady = true;
    });

    function isReady() {
        return bReady;
    }
</script>

//in iframe page
<script>
    var bReady = false;
    while (bReady == false) {
        bReady = window.opener.isReady();
    }
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜