javascript - 从 iframe 获取网站的域名

标签 javascript iframe cross-domain

我正在使用 var url = (window.location!= window.parent.location) ? document.referrer:document.location; 从我的 iframe 中访问网站的域名。令人惊讶的是,这确实有效!但这适用于所有情况吗?

最佳答案

parent.location 适用于所有浏览器:http://www.w3schools.com/jsref/prop_win_parent.asp

关于javascript - 从 iframe 获取网站的域名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12496347/

相关文章:

javascript - 如何使用 JavaScript 选择 <object> 标记内的 SVG 元素?

javascript - 更改对象数组中的键名 - JS

javascript - "$"未定义; jquery 明确链接到 <head> 中;没有冲突的脚本或库

Javascript - 如何使用哈希获取文档引荐来源网址

html - 如何解决跨域安全错误。在 html 5 中使用 Canvas.getImageData

javascript - Firefox 跨域图像被污染

javascript - 表单提交引导后禁用按钮 AngularJs

javascript - 如何在成功函数中为多个语句扩展单个语句

css - 当您显示谷歌地图时,Chrome 会隐藏 iframe 滚动条

javascript - 从 document.ready ie8 设置 iFrame 高度