我有一个 JavaScript 函数,可以在 Internet Explorer 上运行...但不能在 Firefox 或 google chrome 上运行。
这是示例...
function CerrarFrame(src, id, tamArreglo)
{
parent.parent.document.getElementById("workSheet").src = src;
}
现在是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>
这个 javascript 在 IE 上工作正常,但是当我在 FireFox 上使用它时,出现此错误:
TypeError: parent.parent.document.getElementById("workSheet") is null
有办法解决这个问题吗? 谢谢
最佳答案
您似乎想要更改框架 workSheet
的 src
属性。但是,该框架没有 id
,而只有 name
。这就是为什么它在除 IE 之外的所有浏览器中都失败的原因:IE – 至少是 IE 的某些版本 – 在 name
属性和 id
属性之间没有任何区别,这就是它返回的原因物体。您可以将 id
添加到框架(就像您对 frmContent
所做的那样)或使用 frames
集合,例如:
parent.parent.frames["workSheet"].src = src;
使用名称
。请参阅:https://developer.mozilla.org/en-US/docs/DOM/window.frames .
希望有帮助。
关于javascript - 如何在firefox上使用parent.parent.document.getElementById? ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15214271/