如下是一个主page<HTML>
 <body>
 <iframe src ="demoFramesetLeftFrame.html" name="treeframe" id="treeframe" height="100%" width="19%" frameborder="0">
</iframe>
 <iframe src="middle.html" name="middle" id="middle" height="100%" width="10%" frameborder="0">
</iframe>
 <iframe src="demoFramesetRightFrame.html" name="basefrm" id="baseframe" height="100%" width="70%" frameborder="0">
</iframe>
</body></HTML>在middle页面中一一段JavaScript代码想要修改treeframe的宽度,代码如下function sidebar() {
var baseFrame = parent.document.getElementById("baseframe");
var leftFrame = parent.document.getElementById("treeframe");
var colIcon = document.getElementById("sbCol");
var expIcon = document.getElementById("sbExp");
if (leftFrame.width == "0%"){
leftFrame.width = "19%";
baseFrame.width = "70%";
colIcon.style.display = "block";
expIcon.style.display = "none";
}
else{
leftFrame.width = "0%";
baseFrame.width = "89%";
colIcon.style.display = "none";
expIcon.style.display = "block";
}
    }
}通过chrome的js console观察到如下报错信息
Unsafe JavaScript attempt to access frame with URL file:///E:/not%20SAP%E5%BC%80%E5%8F%91%E4%B9%A6%E7%B1%8D/JavaScript/Treeview/demoFrameset.html from frame with URL file:///E:/not%20SAP%E5%BC%80%E5%8F%91%E4%B9%A6%E7%B1%8D/JavaScript/Treeview/middle.html. Domains, protocols and ports must match.
middle.js:2Uncaught TypeError: Cannot call method 'getElementById' of undefined
望高手赐教,给分40,不甚感谢!

解决方案 »

  1.   

    在安全性方面
    chrome跟opera一样采用高安全性(甚至更甚)
    所以要跨frame难度比ff更高在本地跨frame好像是bug... 跨不到的建议你下载一个apache来执行以上代码
      

  2.   

    不過如果只是單純文字資料性質交流的話, 可以考慮用name, name的容量高達2mbmiddle中,
    window.name='loaded'主page中,
    用setInterval判別treeframe的name是否loaded
    然後再在主page執行sidebar的內容
      

  3.   

    应该使用http服务器,不如apache.
    运行在本地浏览器的html,你怎么能load本地文件呢,不安全!
      

  4.   

    推荐用jquery
    解决很多浏览器兼容的问题
      

  5.   

    经测试在tomcat下没有问题!谢谢。
    chrome的高安全性体现在那些方面了?有没有相关文档?
      

  6.   

    为什么在tomcat里就可以了了?
      

  7.   

    chrome 5.0 , 6.0下安全性配置,不允许本地执行文件调用父窗口。配置个apache环境浏览就没问题了