技术开发 频道

frame间的层级调用,如何支持firefox


【IT168技术文档】

  碰到这样的问题,
  我有一个页面main.html,里面有很多的frame,比如说a.html,b.html,c.html,d.html,e.html。。。
  这些子页面,里面都有一个同名javascript的MenuButtonClass()方法
  在其中一个子页面中,我会处理其它的frame是,一般会这样写
window.parent.frames(x).MenuButtonClass();
  这个代码在IE中是没有任何问题的,可是在firefox是错误的!

  后来我这样写了
window.parent.document.getElementsByTagName("frame")[x].MenuButtonClass();
  但是仍然错误,为什么?我调式了,发现
  window.parent.document.getElementsByTagName("frame")[x]是有对象的
  难道还没有其它的东西没写?
  今天终于找到原因了,原来少个contentWindow属性
  所以上面应该这样写

window.parent.document.getElementsByTagName("frame")[x].contentWindow.MenuButtonClass();
  这样的话,支持IE和firefox就没有问题了。 

0
相关文章