我正在尝试将值从父窗口发送到按钮上的框架click
事件,但它在控制台上显示错误
未捕获的安全错误:阻止了具有来源的帧
”http://本地主机:53838 http://localhost:53838” 访问来源为“null”的框架。
请求访问的帧具有“http”协议,该帧是
访问的协议为“文件”。协议必须匹配。
在下面一行:
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>
以及里面的代码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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)