从IFRAME获取当前URL [英] Get current URL from IFRAME

查看:118
本文介绍了从IFRAME获取当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种从iframe获取当前网址的简单方法?

Is there a simple way to get the current URL from an iframe?

观看者将浏览多个网站。
我猜我会用javascript中的东西。

The viewer would going through multiple sites. I'm guessing I would be using something in javascript.

推荐答案

出于安全考虑,你只能得到只要iframe的内容和引用的javascript,就会从同一个域提供url。只要这是真的,这样的东西就可以工作:

For security reasons, you can only get the url for as long as the contents of the iframe, and the referencing javascript, are served from the same domain. As long as that is true, something like this will work:

document.getElementById("iframe_id").contentWindow.location.href

如果这两个域不匹配,您将遇到跨站点引用脚本安全限制。

If the two domains are mismatched, you'll run into cross site reference scripting security restrictions.

另见回答类似的问题

这篇关于从IFRAME获取当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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