12

Web ページでサンドボックスを有効にして iframe を読み込もうとしていますが、エラーが表示されます:

パッドの読み込み中にエラーが発生しました Uncaught SecurityError: 「ドキュメント」で「ドメイン」プロパティを設定できませんでした: サンドボックス化された iframe の割り当ては禁止されています。

iframe を埋め込むコードは次のとおりです。

<iframe 
    id="iframe1" 
    name="iframe1" 
    src="http://localhost:9002/p/6dN6dkWRmd" 
    height="700px" width="500px" 
    sandbox="allow-scripts allow-top-navigation">
</iframe>

iframe javascript で、このコードがエラーをスローしていることがわかりました:

if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0))) { document.domain = document.domain; // コメットの場合 }

document.domainこれが何をしているのか、サンドボックス環境でこの iframe を実行するにはどうすればよいのか、誰か説明してもらえますか?

注:サンドボックスがなくても問題なく動作します。

4

2 に答える 2

0

Document.domain - Web API | MDN」より

Note that setting document.domain to its current value is not a no-op. It still changes the origin. For example, if one page sets
          document.domain = document.domain;
then it will be counted as cross-origin from any other normally-same-origin pages that have not done the same thing.

これにより、同じドメイン上にある場合でも、iframe ページがクロスドメインとして扱われるようになります。

CORS (クロス オリジン) と CSRF (クロス サイト リクエスト フォージェリ) を確認します。

于 2021-07-15T19:26:13.480 に答える