Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 iframe+;对象实例失败_Javascript_Google Chrome_Firefox_Iframe_Microsoft Edge - Fatal编程技术网

Javascript iframe+;对象实例失败

Javascript iframe+;对象实例失败,javascript,google-chrome,firefox,iframe,microsoft-edge,Javascript,Google Chrome,Firefox,Iframe,Microsoft Edge,这让我今天大吃一惊,看看吧: index.html 镶框的 将sandbox2.html更改为 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>instanceof Object FAIL DEMO</

这让我今天大吃一惊,看看吧:

index.html

镶框的

将sandbox2.html更改为

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>instanceof Object FAIL DEMO</h1>
    <div id="foo"></div>
    #foo.bar instanceof Object: <span id="result"></span>
    <br/>
    #foo.bar instanceof parent.Object: <span id="result1"></span>
    <br/>
    typeof #foo.bar: <span id="result2"></span>

    <script>
        document.addEventListener("DOMContentLoaded", function() {
            document.getElementById('foo').bar = { test: 'aaa' };
            setInterval(function() {
                document.getElementById('result').textContent = (document.getElementById('foo').bar instanceof Object).toString();
                document.getElementById('result1').textContent = (document.getElementById('foo').bar instanceof parent.Object).toString();
                document.getElementById('result2').textContent = (typeof document.getElementById('foo').bar).toString();
            }, 100);
        });
    </script>
</body>
</html>

标题
对象实例失败演示
#对象的foo.bar实例:

#父对象的foo.bar实例:
#foo.bar的类型: document.addEventListener(“DOMContentLoaded”,function()){ document.getElementById('foo').bar={test:'aaa'}; setInterval(函数(){ document.getElementById('result').textContent=(document.getElementById('foo').bar instanceof Object.toString(); document.getElementById('result1').textContent=(document.getElementById('foo').bar instanceof parent.Object).toString(); document.getElementById('result2').textContent=(document.getElementById('foo').bar.toString(); }, 100); });

现在您将看到,从主框架开始,iframe中的对象将从instanceOf object更改为instanceOf parent.object-这两个对象是不同的

在真正的javascript
document.getElementById('foo')中,
#foo.bar instanceOf object
是什么意思.bar instanceof Object
它就在sandbox2.html中。当我像您一样创建两个文件时,输出是
#foo.bar instanceof Object:true
typeof#foo.bar:Object
-这是您所期望的吗?是的,这是我所期望的,但您调用了
document.getElementById(“frame”).contentDocument.getElementById吗('foo').bar={}
来自
index.html
中的控制台?这是因为它不再是[window.]对象的实例-它是parent.Object的实例