javascript – Uncaught SecurityError:无法从“HTMLIFrameElement”中读取“contentDocument”属性:阻止源代码“https:// localhost”

我正在面对下面的问题,同时尝试捕获G按钮的点击事件.

未捕获SecurityError:无法从“HTMLIFrameElement”中读取“contentDocument”属性:阻止源“https://localhost”的帧访问原始帧“https://apis.google.com”.协议,域和端口必须匹配.

我发现了类似的讨论,Uncaught SecurityError: Failed to read the ‘contentDocument’ property from ‘HTMLIFram.

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

Mozilla’s Same Origin article

For fix this, you will need to add this code

document.domain = 'yourdomain.com'

从文章本身:

A page may change its own origin with some limitations. A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks. For example, assume a script in the document at 07002 executes the following statement:

document.domain = "company.com";

After that statement executes, the page would pass the origin check with 07003. However, by the same reasoning, company.com could not set document.domain to othercompany.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.

翻译自:https://stackoverflow.com/questions/28272933/uncaught-securityerror-failed-to-read-the-contentdocument-property-from-html

转载注明原文:javascript – Uncaught SecurityError:无法从“HTMLIFrameElement”中读取“contentDocument”属性:阻止源代码“https:// localhost”