javascript - 在子域 iframe 中更改窗口位置 href
问题描述
我有a.example.com
和b.example.com
;
当我将b.example.com/foo
iframe 放入a.example.com
:
<iframe src='b.example.com/foo'></iframe>`
window.location.href
可访问的值b.example.com
是 ... a.example.com/foo
(??)...
问题是 - 我使用了一个外部库b.example.com/foo
来检查window.location.href
它并得到不正确的信息。
对于这种情况,在我看来,我应该/foo
在一个完全不同的域上 iframe 内容,例如:
anotherexample.com/foo
,window.location.href
实际指向anotherexample.com/foo
.
如何强制 iframe 中的窗口对象实际使用其子域而不是添加参数的父域?
解决方案
你确定你在正确的子域中使用你的脚本吗?似乎您的外部库正在使用 访问父窗口window.parent.location
,这是检查页面是直接加载还是在另一个页面中加载的代码:
var is_loaded_directly = (window.location == window.parent.location);
由于此代码有效,因此您的设置或库有问题。
注意:也许您可以通过检查document.location
而不是window.location
.
推荐阅读
- angular - OpenLayers 4 extent.extend 替换
- java - 如何用方法注入替换装饰器中的构造函数注入以获取链接并使现有代码按原样工作?
- css - 使用 CSS 对悬停时的图像进行模糊处理
- docker - Kubernetes Pod 停留在“待定状态”:“错误:手表在超时前关闭”
- java - 从 OWL Ontology 获取部分课程
- sqlplus - 什么是“JVAL:kolrcrfc durid = 10”,我该如何摆脱它?
- c# - AspNet Core 2.2 Windows 身份验证 - 浏览器不断提示输入用户名和密码
- arrays - Ruby:从字符串数组的每个元素中获取字符[n],严格使用数组表示法
- typescript - 如何从单独的“包含”目录加载模块?
- excel - Excel VLookup - 文本键完全匹配数值不完全匹配