我用IFrame中的问题,在主页面提控制子页面的地址和CSS
不知那里出错了~! <HTML> 
<HEAD> 
<TITLE> Test Page </TITLE> 
</HEAD> 
<BODY>
<script>function   cSrc(url) 

var   ifm=document.getElementById( "test") 
ifm.src=url; 
}
function aaa(){
    var newlink = document.frames["test"].document.createElement("link");
var   ifm=document.getElementById( "test") 
ifm.src=url; 
newlink.setAttribute("rel", "stylesheet");
    newlink.setAttribute("type", "text/css");
    newlink.setAttribute("href", document.getElementById("link1").href);
    document.frames["test"].document.body.appendChild(newlink);}
</script><link id="link1" rel="stylesheet" type="text/css" href="test.css"><div>测试文字</div>
<a href="#" onclick= "aaa('b.html')"> b</a>
<iframe name="test" src="b.html" ></iframe>
</BODY> 
</HTML>

解决方案 »

  1.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link id="cssLink" rel="stylesheet" type="text/css" href="test.css">
    <script type="text/javascript">
    function aaa(url){
    var ifm = document.getElementById("test");
    ifm.src = url;
    var newlink = document.createElement("link");
    newlink.setAttribute("rel", "stylesheet");
    newlink.setAttribute("type", "text/css");
    newlink.setAttribute("href", document.getElementById("cssLink").href);
    (ifm.document || ifm.contentWindow.document).getElementsByTagName('head')[0].appendChild(newlink);
    }
    </script>
    </head>
    <body>
    <a href="#" onclick="aaa('inner.html')"> b</a>
    <iframe id="test"></iframe>
    </body>
    </html>
      

  2.   

    没有把CSS的样式专到IFRAME去哦
      

  3.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link id="cssLink" rel="stylesheet" type="text/css" href="test.css">
    <title></title>
    <script type="text/javascript">
    function changeURL(url){
    document.getElementById("test").src = url;
    }
    function _load(ifm){
    var newlink = document.createElement("link");
    newlink.setAttribute("rel", "stylesheet");
    newlink.setAttribute("type", "text/css");
    newlink.setAttribute("href", document.getElementById("cssLink").href);
    (ifm.document || ifm.contentWindow.document).getElementsByTagName('head')[0].appendChild(newlink);
    }
    </script>
    </head>
    <body>
    <a href="#" onclick="changeURL('inner.html')">b</a>
    <iframe id="test" onload="_load(this);"></iframe>
    </body>
    </html>