Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.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在子框架中编写?_Javascript_Parent Child_Getelementbyid_Frames - Fatal编程技术网

用Javascript在子框架中编写?

用Javascript在子框架中编写?,javascript,parent-child,getelementbyid,frames,Javascript,Parent Child,Getelementbyid,Frames,我需要在页面加载开始时运行一个函数,但它根本不起作用。 我有一个父HTML(称为main)和三个框架(childs frameA、frameB、frameC) main.html: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <

我需要在页面加载开始时运行一个函数,但它根本不起作用。 我有一个父HTML(称为main)和三个框架(childs frameA、frameB、frameC)

main.html:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <script type="text/javascript" src="js/main.js"></script>
    <title></title>
    </head>
    <frameset cols="40%,*">
    <frameset rows="55%,45%">
            <frame src="frameA.html" name="frameA" id="frameA" />
            <frame src="frameB.html" name="frameB" id="frameB" />
        </frameset>
            <frame src="frameC.html" name="frameC" id="frameC" />
    </frameset>
    </html>

我厌倦了“名字是空的”。为什么会发生这种情况?

将js脚本向下移动到框架集下方,它应该可以工作

就在结束标记之前


我认为这是因为文档已经加载到你的js可以看到框架元素的地方…

很抱歉这个答案含糊不清,但上次我不得不这样做时,我无法直接写入框架,但我必须在框架内来回传递信息。下面是一个如何执行此操作的示例:。因此,基本上,您必须在iframe中有一个函数来调用以进行编写。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <title>FrameA</title>
    </head>
    <body>
    <h1>FRAME A</h1>
    </body>
    </html>
    function resetC() {
        var oFrame = document.getElementById('frameC');
        oFrame.document.write("Frame C reseted");
    }
    resetC();