不安全的JavaScript尝试使用网址访问框架 [英] Unsafe JavaScript attempt to access frame with URL

查看:136
本文介绍了不安全的JavaScript尝试使用网址访问框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下错误,当我尝试设置哈希值到父网址从iframe其中包含另一个域url:

I am getting the below error when i try to set a hash value to the parent url from iframe which contains another domain url:


不安全的JavaScript尝试从带有URLURL2的框架中访问带有URLURL1的框架。域/协议和端口必须匹配。

Unsafe JavaScript attempt to access frame with URL "URL1" from frame with URL "URL2". Domains, protocols and ports must match.

如何解决此问题?

推荐答案

从不同来源的子文档,您不能访问顶部窗口的 location.hash 属性,允许设置位置属性本身。

From a child document of different origin you are not allowed access to the top window's location.hash property, but you are allowed to set the location property itself.

这意味着由于顶部窗口位置 http://example.com/page/ ,而不是

This means that given that the top windows location is http://example.com/page/, instead of doing

parent.location.hash = "#foobar";

你需要知道父母的位置,然后

you do need to know the parents location and do

parent.location = "http://example.com/page/#foobar";

由于资源未导航,这将按预期工作,只更改url的哈希部分。

Since the resource is not navigated this will work as expected, only changing the hash part of the url.

如果您使用此网域进行跨网域通讯,那么我建议您使用 easyXDM

If you are using this for cross-domain communication, then I would recommend using easyXDM instead.

这篇关于不安全的JavaScript尝试使用网址访问框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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