我正在使用Iframe Resizer并且我的代码无法跨域工作。当两个域相同时,它可以正常工作。你能帮我吗?这很奇怪,因为iframe确实加载了iFrameResizer.contentWindow.js,并且我使用了checkOrigin:false,所以它应该允许跨域...

这是加载具有iframe的父页面时在控制台中出现的错误:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://jacobjohnson.net') does not match the recipient window's origin ('http://designtesting.cfs.local').iframeResizer.min.js:8 [iFrameSizer][Host page: display_frame] No response from iFrame. Check iFrameResizer.contentWindow.js has been loaded in iFrame

<div class="panel panel-default" id="iframePanel">
    <div class="panel-body" style="padding:0px;">
       <iframe id="display_frame" name="display_frame" class="frame" src="http://jacobjohnson.net/iframetest.html" allowfullscreen></iframe>
    </div>
</div>


<script>

    jQuery('#display_frame').iFrameResize( [{log:true, checkOrigin: false}] );

    var frameHeight =  3905; // $('#display_frame').height();
    var newHeight = frameHeight / 2;
    $('#iframePanel').height(newHeight);

    $(window).resize( function() {
        var frameHeight = $('#display_frame').height();
        var newHeight = frameHeight / 2;
        $('#iframePanel').height(newHeight);
    });

</script>

最佳答案

您的电话应该如下。

jQuery('#display_frame').iFrameResize({log:true, checkOrigin: false});

07-24 18:06