Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在铬合金中,can';t访问子iframe或iframe'的任何变量或函数;父母_Javascript_Google Chrome_Iframe_Parent - Fatal编程技术网

Javascript 在铬合金中,can';t访问子iframe或iframe'的任何变量或函数;父母

Javascript 在铬合金中,can';t访问子iframe或iframe'的任何变量或函数;父母,javascript,google-chrome,iframe,parent,Javascript,Google Chrome,Iframe,Parent,这与类似,但范围更广 我只是在本地打开这些页面,它们位于同一个文件夹中 index.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <title>TestIndex</title>

这与类似,但范围更广

我只是在本地打开这些页面,它们位于同一个文件夹中

index.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
    <head>
        <title>TestIndex</title>
        <script type="text/javascript">
            function init()
            {
                alert("child.childvar: " + child.childvar); //works in FF, IE, not Chrome
                alert("frames['child'].childvar: " + frames['child'].childvar); //works in FF, IE, not Chrome
                alert("document.getElementById('child').contentWindow['childvar']: " + document.getElementById('child').contentWindow['childvar']); //works in FF, IE, not Chrome

                child.childfunc(); //works in FF, IE, not Chrome
                frames['child'].childfunc(); //works in FF, IE, not Chrome
                document.getElementById('child').contentWindow['childfunc()']; //doesn't work in anything
            }

            var parentvar = 7;
            function parentfunc()
            {
                alert("In parentfunc");
            }
            window.onload = init;
        </script>
    </head>

    <body>
        <iframe id="child" name="child" src="child.html">Your browser does not support iframes</iframe>
    </body>
</html>

睾丸指数
函数init()
{
警报(“child.childvar:+child.childvar);//适用于FF,IE,而不是Chrome
警报(“frames['child'].childvar:+frames['child'].childvar);//适用于FF,即不适用于Chrome
警报(“document.getElementById('child').contentWindow['childvar']:”+document.getElementById('child').contentWindow['childvar']);//适用于FF,IE,而不是Chrome
child.childfunc();//适用于FF,IE,而不是Chrome
frames['child'].childfunc();//适用于FF,IE,而不是Chrome
document.getElementById('child').contentWindow['childfunc()'];//在任何情况下都不起作用
}
var=7;
函数parentfunc()
{
警报(“在parentfunc中”);
}
window.onload=init;
您的浏览器不支持iFrame
child.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
    <head>
        <title>TestChild</title>
        <script type="text/javascript">
            function init()
            {
                alert("parent.parentvar: " + parent.parentvar); //works in FF, IE, not Chrome

                parent.parentfunc(); //works in FF, IE, not Chrome
            }

            var childvar = 5;
            function childfunc()
            {
                alert("In childfunc");
            }
            window.onload = init;
        </script>
    </head>

<body>

</body>
</html>

测试儿童
函数init()
{
警报(“parent.parentvar:+parent.parentvar);//适用于FF,IE,而不是Chrome
parent.parentfunc();//适用于FF,IE,而不是Chrome
}
var=5;
函数childfunc()
{
警报(“在childfunc中”);
}
window.onload=init;
在chrome中,我似乎无法实现页面与其iframe内容之间的任何通信。我确实阅读了我链接的问题的答案,但我真的不知道什么是用户脚本/内容脚本,所以我不知道这些问题与我的问题有多相关


我想我真正的问题是:我他妈的怎么从一个iframe的页面中获取值到父页面中呢

显然,javascript帧间通信在本地文件系统上不起作用。将文件放在服务器上,它可能会按预期运行。

显然,在本地文件系统上,javascript帧间通信不起作用。将文件放在服务器上,它很可能会按预期运行。

Wooo,tumbleweed!值得一提的是,我把它作为一个问题记录在这里:哇,风滚草!值得一提的是,我将此作为一个问题记录在这里:您是如何发现这一点的?目前没有时间测试这个(已经转移到一个新项目),但出于好奇,我会在某个阶段尝试一下。是的,这是正确的。很抱歉,我花了这么长时间来测试和接受这个!你是怎么发现的?目前没有时间测试这个(已经转移到一个新项目),但出于好奇,我会在某个阶段尝试一下。是的,这是正确的。很抱歉,我花了这么长时间来测试和接受这个!