知道用户在iframe中浏览的页面 [英] Know which page the user is browsing in iframe

查看:94
本文介绍了知道用户在iframe中浏览的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个网页,这是一个主页面,其中包含一个iframe,其内容不是来自与主页面相同的主机,但我想知道用户当前在iframe中浏览的页面。

I would like to create a web page which is a main page that has one iframe whose content does not come from the same host as the main page but I would like to know which page the user is currently browsing in the iframe.

例如,我有一个主页面,其中包含一个绑定了Javascript事件的按钮,以及一个从谷歌等网站加载内容的iframe。

For example, I have a main page with a button bound with an Javascript event and an iframe that load content from a site like google.

用户可以根据需要导航iframe中的内容,但是当点击主页面中的按钮时,必须弹出iframe中的当前网址。

A user can navigate the content in iframe as he wants but when the button in the main page is clicked, the current url in the iframe must be popped up.

我已经尝试了但是由于相同的原始政策始终适用,因此会发生类似这样的错误
拒绝访问属性'location'的权限
我知道根据SOP它是有道理的,但我真的需要这样做。
我想知道是否有一些黑客可以做到这一点,或者我必须承认
限制并以其他方式设计我的应用程序。

I already tried it but since the same origin policy always applies, an error like this Permission denied to access property 'location' occurs. I do know that it makes sense according to SOP but I really need to do it. I would like to know if there is some hack that can do the trick or I have to admit the restriction and design my app the other way.

推荐答案

如果有这样的伎俩,它会使浏览器安全无效并暴露隐私问题。这些都是有原因的。

If there was such a trick, it would make browser security invalid and expose privacy issues. These things are there for a reason.

您可以为自己禁用此功能,但是为其他人绕过它是邪恶的。

You can disable this for YOURSELF, but bypassing it for others is evil.

请参阅:

禁用相同功能Chrome中的原始政策

这篇关于知道用户在iframe中浏览的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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