javascript 如何在 Firefox 上使用 parent.parent.document.getElementById?网站

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15214271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:53:50  来源:igfitidea点击:

how to use parent.parent.document.getElementById on firefox?? asp.net

javascriptasp.netfirefoxframegetelementbyid

提问by Victor

i have a javascript function that does work on Internet Explorer... but doesn't work on firefox nor google chrome.

我有一个可以在 Internet Explorer 上运行的 javascript 函数......但在 Firefox 和 google chrome 上都不起作用。

Here's the example...

这是例子...

function CerrarFrame(src, id, tamArreglo)
{
    parent.parent.document.getElementById("workSheet").src = src;
}

now the asp form

现在是asp形式

<frameset rows="41, *" frameborder="0" framespacing="0" name="frmMain" id="frmMain">
    <frame name="topForm" src="Header.aspx" marginheight="0" marginwidth="0" scrolling="no" noresize>

    <frameset cols="168,*" frameborder="0" framespacing="0" id="frmBody">
        <frame name="frmMenu" id="frmMenu" src="MenuFrameNew.aspx?idUser=<%Response.Write(Session["idUser"]);%>&administrator=<%Response.Write(Session["administrator"]);%>&idCorp=<%Response.Write(Session["idCorporative"]);%>&file=<%Response.Write(Session["fileLogo"]);%>" marginheight="0" marginwidth="0" scrolling="no" noresize>

        <frameset id="frmContent" name="frmContent" rows="*,21" frameborder="0" framespacing="0">
            <frame name="workSheet" marginheight="0" marginwidth="0" src="Body.aspx" scrolling="auto">
            <frame name="btm" marginheight="0" marginwidth="0" src="footer.htm" scrolling="no">
        </frameset>
    </frameset>
</frameset>

This javascript works properly on IE, but when I use it on FireFox, I get this error:

这个 javascript 在 IE 上可以正常工作,但是当我在 FireFox 上使用它时,出现此错误:

TypeError: parent.parent.document.getElementById("workSheet") is null

Is there a way to work this around? Thanks

有没有办法解决这个问题?谢谢

采纳答案by ZER0

It seems you want to change the srcattribute of the frame workSheet. However, that frame doesn't have an idbut just a name. That's why it fails in all browsers but IE: IE – at least some version of IE – doesn't make any difference between nameattribute and idattribute, that's why it returns the object. You can either add an idto the frame (as you have done with frmContent) or using framescollection, like:

看来您要更改srcframe的属性workSheet。但是,该框架没有,id而只有name. 这就是它在除 IE 之外的所有浏览器中都失败的原因:IE——至少是某些版本的 IE——在name属性和id属性之间没有任何区别,这就是它返回对象的原因。您可以id向框架添加 一个(就像您对 所做的那样frmContent)或使用frames集合,例如:

parent.parent.frames["workSheet"].src = src;

That uses the name. See: https://developer.mozilla.org/en-US/docs/DOM/window.frames.

那使用name. 请参阅:https: //developer.mozilla.org/en-US/docs/DOM/window.frames

Hope it helps.

希望能帮助到你。