相关疑难解决方法(0)

SecurityError:阻止具有原点的帧访问跨源帧

我正在<iframe>我的HTML页面中加载一个并尝试使用Javascript访问其中的元素,但是当我尝试执行我的代码时,我收到以下错误:

SecurityError: Blocked a frame with origin "http://www.<domain>.com" from accessing a cross-origin frame.
Run Code Online (Sandbox Code Playgroud)

你能帮我找一个解决方案,以便我可以访问框架中的元素吗?

我正在使用此代码进行测试,但徒劳无功:

$(document).ready(function() {
    var iframeWindow = document.getElementById("my-iframe-id").contentWindow;

    iframeWindow.addEventListener("load", function() {
        var doc = iframe.contentDocument || iframe.contentWindow.document;
        var target = doc.getElementById("my-target-id");

        target.innerHTML = "Found it!";
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript iframe jquery same-origin-policy

487
推荐指数
4
解决办法
82万
查看次数

Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了一个源为"https:// localhost"的帧

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

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

javascript securityexception

20
推荐指数
1
解决办法
6万
查看次数