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

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

问题描述

有没有一种简单的方法可以从 iframe 中获取当前 URL?

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.

推荐答案

出于安全原因,您只能获取 url,只要 iframe 的内容和引用的 javascript 来自同一域.只要这是真的,这样的事情就会起作用:

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天全站免登陆