反应中的同源政策,为什么这有效?
Same-origin policy in react, Why is this working though?
这是我在这里的第一个问题(经过多年浏览网站)。
我发现了一个带有反应组件的柱塞加载 iframe 并允许将 iframe 的来源更改为另一个来源。
柱塞Link:http://plnkr.co/edit/GRkvbJssZbWDWLfjHB7i?p=preview
var Componentnt = React.createClass({
render: function() {
var Iframe = this.props.iframe;
return (
< div >
< Iframe src = {
this.props.src
}
height = {
this.props.height
}
width = {
this.props.width
}
/>
< /div>
)
}
});
ReactDOM.render(
//Change this to https://www.cnn.com/
< Componentnt iframe = 'iframe'
src = "https://www.usatoday.com/"
height = "500px"
width = "100%" / > ,
document.getElementById('example')
);`
根据同源策略,难道不应该因此而阻止 iframe 源的更改吗?
如果有人能为我解释一下,那就太好了。
谢谢大家!
如果您有权访问 iframe 页面内容,请将您的域添加到文档中以获取访问权限。
<script>
document.domain = 'external-domain.tld'
</script>
这是我在这里的第一个问题(经过多年浏览网站)。
我发现了一个带有反应组件的柱塞加载 iframe 并允许将 iframe 的来源更改为另一个来源。
柱塞Link:http://plnkr.co/edit/GRkvbJssZbWDWLfjHB7i?p=preview
var Componentnt = React.createClass({
render: function() {
var Iframe = this.props.iframe;
return (
< div >
< Iframe src = {
this.props.src
}
height = {
this.props.height
}
width = {
this.props.width
}
/>
< /div>
)
}
});
ReactDOM.render(
//Change this to https://www.cnn.com/
< Componentnt iframe = 'iframe'
src = "https://www.usatoday.com/"
height = "500px"
width = "100%" / > ,
document.getElementById('example')
);`
根据同源策略,难道不应该因此而阻止 iframe 源的更改吗?
如果有人能为我解释一下,那就太好了。
谢谢大家!
如果您有权访问 iframe 页面内容,请将您的域添加到文档中以获取访问权限。
<script>
document.domain = 'external-domain.tld'
</script>