6

基本的に、コンテンツが同じオリジンからのものであっても、コンテンツが別のドメインからのものであるかのように常に制限する iFrame が必要です。

これを行う方法はありますか?

4

2 に答える 2

1

これはwindow.parent子フレーム/ウィンドウでは非表示になりますが、topプロパティでは非表示になります。

window.parentただし、子ウィンドウ/フレームの onload イベントが終了するまで、プロパティには引き続きアクセスできます。

<html>
  <head>
    <style type="text/css">
      #wrapper {width:1000px;height:600px;}
    </style>
    <script type="text/javascript">
      window.onload = function() {
        var frm = document.getElementById('childFrame');
        var win = frm.contentWindow || (frm.contentDocument && frm.contentDocument.parentWindow) || (frm.document && frm.document.parentWindow);
        if (win) win.parent = null;
      }
    </script>
  </head>
  <body>
    <div id="wrapper">
      <iframe id="childFrame" src="child.html" frameborder="0" style="width:100%;height:100%;"></iframe>
    </div>
  </body>
</html>
于 2012-11-06T10:19:38.657 に答える