更改iframe位置时更改窗口位置 [英] change window location when iframe location is changed

查看:98
本文介绍了更改iframe位置时更改窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使iframe内的页面不是src,那么它将父页面更改为iframe试图访问的url?像这样:

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>

推荐答案

否.

根据同源政策,除非父页面位于同一域中,否则不允许其父页面获取有关iframe中运行状况的任何信息.

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.

这篇关于更改iframe位置时更改窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆