change window location when iframe location is changed

无人久伴 提交于 2019-12-11 16:50:46

问题


Is there a way to make it so that if the page inside an iframe is not the src, then it will change the parent page to the url the iframe is trying to go to? Something like this:

<script>
function redir() {
    if(document.getElementById("myiframe").src != 'http://www.google.com'){
        window.location = document.getElementById("myiframe").location
    }
}
</script>
<iframe src="http://www.google.com/" id="google" onload="redir()"></iframe>

回答1:


No.

Per the same-origin policy, the parent page is not allowed to get any information about what's going in the iframe, unless the pages are on the same domain.



来源:https://stackoverflow.com/questions/5366770/change-window-location-when-iframe-location-is-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!