2017-10-20 9 views
0

同じ起源のポリシーについて知りたいです。それについて話しているsiteがあります。しかし、sthする必要があります。同じ起点のポリシーエラー

http://www.qnimate.com/parent.htmlにある親サイト:私はここでエラーにIllegal document.domain value

を得たので最初の例と間違っ問題のあるコードがある

<iframe src="http://www.blog.qnimate.com/child.html" id="myIFrame"></iframe> 
<script> 
window.document.domain = "www.qnimate.com";//you also need to set the parent's document.domain variable 
window.document.getElementById("myIFrame").contentWindow.document.body.style.backgroundColor = "red";//this access is allowed by default 
</script> 

http://www.blog.qnimate.com/child.htmlに位置IFRAME:

<script> 
window.document.domain = "www.qnimate.com"; //if we remove this line then the below line will not work and throw a same origin policy exception. 
window.parent.document.body.style.backgroundColor = "blue"; 
</script> 

答えて

0

document.domainは、現在のドメインのスーパードメインにのみ設定できます。コンポーネントは左端から削除できます。

現在のドメインはwww.blog.qnimate.comですので、blog.qnimate.comまたはqnimate.comに設定することができます。

真ん中のコンポーネントを削除することはできませんので、www.qnimate.comは使用できません。


in this questionが記載されているようにpostMessageを使用し、インラインフレームを介して異なる起源を横切って通信します。

+0

上記の例は正しくありませんか? – Mulligun81

+0

@ Mulligun81 - はい。あなたが観察したサンプルコードは、エラーをスローします。 – Quentin

関連する問題