由于不匹配协议而阻止了iframe



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

未经安全性:阻止了用原点的框架 " http://localhost:53838"从访问原点" null"的框架中。 请求访问的框架具有" http"协议,框架为 访问的协议的"文件"协议。协议必须匹配。

在以下行:

window.parent.setUpFrame();

我在 parent Container 中具有以下代码:

<!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>

和内部的代码 frame 看起来像这样:

<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。

似乎您是通过文件协议访问" main" -html(只需双击html?)。

请尝试通过http://localhost:53838/以及通过file-protocol加载iframe。

最新更新