未捕获的SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了具有原点的帧“https:// localhost” [英] Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://localhost"

查看:239
本文介绍了未捕获的SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了具有原点的帧“https:// localhost”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试捕获G +跟随按钮的点击事件时面临以下问题。

I am facing below issue while trying to capture click events of G + follow button.

Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止具有原点 https:// localhost 的框架访问具有来源 https://apis.google.com 。协议,域和端口必须匹配。

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://localhost" from accessing a frame with origin "https://apis.google.com". Protocols, domains, and ports must match.

推荐答案

我发现了类似的讨论, Uncaught SecurityError:无法从''读取'contentDocument'属性HTMLIFram

I found a similar discussion, Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFram.


当您尝试将ajax调用到另一个域时会触发此问题,请查看此文章以获取有关Same的更多信息原始政策

This issue fired when you try to call ajax to another domain, please check this article for more info about Same origin policy

Mozilla的同源文章


为了解决这个问题,你需要添加此代码

For fix this, you will need to add this code



document.domain = 'yourdomain.com'

来自文章本身:


页面可能会因某些限制而改变自己的起源。脚本可以将document.domain的值设置为当前域的子集。如果它这样做,则较短的域用于后续的原始检查。例如,假设文档中的脚本位于 http://store.company.com/dir/other .html 执行以下语句:



document.domain = "company.com";




执行该语句后,页面将通过原点检查< a href =http://company.com/dir/page.html =noreferrer> http://company.com/dir/page.html 。但是,出于同样的原因,company.com无法将document.domain设置为othercompany.com。

After that statement executes, the page would pass the origin check with http://company.com/dir/page.html. However, by the same reasoning, company.com could not set document.domain to othercompany.com.

端口号由浏览器单独保存。对setter的任何调用,包括document.domain = document.domain都会导致端口号被null覆盖。因此,只能在第一个中设置document.domain =company.com,无法使company.com:8080与company.com交谈。必须在两者中设置它,以便端口号都为空。

The port number is kept separately by the browser. Any call to the setter, including document.domain = document.domain causes the port number to be overwritten with null. Therefore one cannot make company.com:8080 talk to company.com by only setting document.domain = "company.com" in the first. It has to be set in both so that port numbers are both null.

这篇关于未捕获的SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了具有原点的帧“https:// localhost”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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