10

広範な調査の結果、これは機能するはずですが、IE8ではletsgo関数が呼び出されません...何か助けはありますか?

<script type="text/javascript">
    function resizeCrossDomainIframe() {        

        if (window.addEventListener) {
            window.addEventListener('message', letsgo, false);
        } else if (window.attachEvent) {
            window.attachEvent('onmessage', letsgo);
        }
    }
    function letsgo(event) {
        var iframe = document.getElementById('my_iframe');
        if (event.origin !== 'http://mysite.com') return; // only accept messages from the specified domain
        if (isNaN(event.data)) return; // only accept something which can be parsed as a number
        var height = parseInt(event.data) + 32; // add some extra height to avoid scrollbar
        iframe.height = height + "px";
    }
</script>
    <iframe src='http://mysite.com/products/default.aspx?iframe=true&partnerid=222&site=localhost:62014' frameborder="0" width="100%" scrolling="auto" style="min-height: 750px; min-width: 600px; background-color: #fff;"  id="my_iframe" onload="resizeCrossDomainIframe();">
    </iframe>
4

1 に答える 1

7

わかりました、競合状態だったに違いありません。オンロードを取り出しました。

<script type="text/javascript">


        if (window.addEventListener) {
            window.addEventListener('message', letsgo, false);
        } else if (window.attachEvent) {
            window.attachEvent('onmessage', letsgo);
        }

    function letsgo(event) {
        var iframe = document.getElementById('my_iframe');
        if (event.origin !== 'http://mysite.com') return; // only accept messages from the specified domain
        if (isNaN(event.data)) return; // only accept something which can be parsed as a number
        var height = parseInt(event.data) + 32; // add some extra height to avoid scrollbar
        iframe.height = height + "px";
    }
</script>
    <iframe src='http://mysite.com/products/default.aspx?iframe=true&partnerid=222&site=localhost:62014' frameborder="0" width="100%" scrolling="auto" style="min-height: 750px; min-width: 600px; background-color: #fff;"  id="my_iframe" >
    </iframe>
于 2013-02-05T19:36:58.633 に答える