1. 程式人生 > >js在frame中操作frameset的cols屬性的改變

js在frame中操作frameset的cols屬性的改變

目標:單擊圖片使用左邊的frame收縮。

<frameset rows="89,*" frameborder="0" framespacing="0" border="0" style=" overflow:hidden">
<frame src="header.html">
<frameset cols="235,7,*" id="bottom">
<frame src="control.html" style="overflow-x:hidden">
<frame src="switch.html" name="switch" frameborder="no" scrolling="no" noresize="">
<frame src="addGoods.html">
</frameset>

其中switch.html對應的程式碼如下:
<html>
<head>
<title>摺疊/展開</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"> 
function changeWin(){	
	if(window.parent.bottom.cols == "235,7,*")
	{
		top.bottom.cols = "0,7,*";
		document.getElementById('menuSwitch').innerHTML = "<img src='../images/cc2.gif' width=6 height=50>";
	}
	else
	{
		top.bottom.cols = "235,7,*";
		document.getElementById('menuSwitch').innerHTML = "<img src='../images/cc.gif' width=6 height=50>";
	}
}
</script>
</head>

<body bgcolor="#EEEEEE" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" oncontextmenu="return false">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
	<tbody>
    <tr> 
      <td> 
		<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
		  <tbody>
          <tr> 
          <td width="100%" height="100%" id="menuSwitch" onClick="changeWin()" title="摺疊/展開選單" style="cursor:pointer"><img src="../images/cc.gif" name="ff" width="6" height="50"></td>
		  </tr>
	    </tbody>
        </table>
	  </td>
	  <td height="100%" width="1" bgcolor="#dddddd"></td>
    </tr>
	</tbody>
</table>

</body>
</html>

在IE和firefox裡才能正常使用,唯獨chrome報錯: Uncaught TypeError: Cannot read property 'cols' of undefined

不安全?我汗,怎麼也不知道怎麼解決,後來在一文中找到答案,放在tomcat裡就完全正常了,再汗。。。