从不同域中的框架/iframe 获取顶部窗口 url [英] Get top window url from frame/iframe in different domain

查看:58
本文介绍了从不同域中的框架/iframe 获取顶部窗口 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,里面有一些 javascript,它将作为 iframe 嵌入到不同的网站中.我需要根据运行它的网站调整我的页面的行为.为此,我尝试从我的页面读取 top.location.href,但这引发了错误:

I have a web page with some javascript inside that will be embedded as iframe in different websites. I need to adjust the behaviour of my page according to the website in which it's being run. For this purpose, I tried to read top.location.href from my page, but that raised an error:

不安全的 JavaScript 尝试使用 URL http://website.url 访问框架来自 URL http://mypage.url 的框架.域、协议和端口必须匹配.

Unsafe JavaScript attempt to access frame with URL http://website.url from frame with URL http://mypage.url. Domains, protocols and ports must match.

有什么办法可以解决这个问题吗?

Is there some way to go around this?

推荐答案

这与您所说的同源策略相同,并且出于安全原因而实施.如果不更改用户浏览器,就没有办法解决.

This is as you stated the same origin policy and it is in place for security reasons. Without changing the users browser there is no way around it.

这篇关于从不同域中的框架/iframe 获取顶部窗口 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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