案例1: 做一个通用的反馈表单应用在其它页面的框架里, 要求在框架外面可以定义框架里面的页面样式。
程序代码
<iframe name="feedbackform" id="feedbackform" src="xx.aspx" mce_src="xx.aspx" width="755" height="500" marginheight="0" marginwidth="0" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript"> var temp_css; temp_css="<style type=\"text/css\">"; temp_css+="body{padding:10px 0;margin:0;font-size:12px;}"; temp_css+="</style>"; window.onload=function(){ var obj=window.frames["feedbackform"]; obj.document.body.innerHTML+=temp_css; } </script>
案例2: 例:需要在a.html中去改变b.html中.abc的色彩。
a.html <iframe src="b.html" mce_src="b.html" id="content" name="content" height="15" width="468" scrolling="no" frameborder="0"></iframe> <script type="text/javascript"> document.frames['content'].document.styleSheets[0].addRule(".abc","color:#FF0000");</script>
b.html <style>.abc{color:#000000}</style>