由于不匹配的协议,iframe被阻止 [英] Blocked iframe due to mismatch protocols

查看:72
本文介绍了由于不匹配的协议,iframe被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将父窗口中的值发送到按钮 click 事件上的框,但是在控制台上显示错误

I am trying to send a value from parent window to my frame on button click event but it shows error on the console

未捕获到的SecurityError:阻止了具有原点的帧" http://localhost:53838 ",访问源为"null"的框架.请求访问的帧的协议为"http",该帧为访问的协议为文件".协议必须匹配.

Uncaught SecurityError: Blocked a frame with origin "http://localhost:53838" from accessing a frame with origin "null". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "file". Protocols must match.

在以下行上:

window.parent.setUpFrame();

我在父容器中有以下代码:

<!DOCTYPE html>
<html>
<head>

<script>
function setUpFrame() { 
    var frame = window.frames['myFrame'];
    $('#btn-violet').click(function () {
        frame.changeTheme(2);
    });
}
</script>

</head>
<body>

<iframe id="myFrame" width="100%" height="300px" src="http://localhost:53838/" name="iframe_a"></iframe>    <input type="button" value="bisque Theme" id="btn-bisque" />
<input type="button" value="violet theme" id="btn-violet" />

</body>
</html>

框架中的代码如下:

<script>
        function init()
        {
            window.parent.setUpFrame();
            return true;
        }

        function changeTheme(id)
        {
            if (id == 1) {
                $('#CustomStyle').attr('href', '/Content/StyleSheet1.css');
            }
            else
            {
                $('#CustomStyle').attr('href', '/Content/StyleSheet2.css');
            }
        }
</script>

推荐答案

如果通过文件提供了父页面,那就是问题所在.您不能将文件页面与http嵌套框架混合使用.您还应该从文件中加载iframe.

If your parent page is served through file this is the problem. You cannot mix a file page with an http nested frame. You should load the iframe from file as well.

这篇关于由于不匹配的协议,iframe被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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