test.htm
<HTML>
<head>
<title>test</title>
<style type=text/CSS id=fatherStyle>
body {background:#efefef}
.s1 {background: red}
</style>
</head>
<body>
<input type=button value=open onclick=window.open('son.htm','')>
</body>
</HTML>
------------------------------------------
son.htm
<HTML>
<HEAD><TITLE></TITLE>
<style type=text/CSS id=sonStyle>
</style>
<script>
bgd=opener.document.styleSheets(0).rules(1).style.background;
name=opener.document.styleSheets(0).rules(1).selectorText;
document.styleSheets.sonStyle.addRule(name,"background:"+bgd);
//以上几条语句使得本页面可以使用父窗口定义的s1,但是这很麻烦,有什么简单的办法可以继承父窗口定义的所有styleSheets吗?象下面的语句就出错:
//document.styleSheets.sonStyle.rules=opener.document.styleSheets.fatherStyle.rules;
function changeStyle(){
d1.className="s1";
}
</script>
</HEAD>
<BODY>
<span id=d1>测试文字</span><br>
<input type=button value=change onClick=changeStyle()>
</body>
</HTML>