2012-02-08 71 views
1

更改字體大小我的iFrame是這樣的:裏面的iframe

<iframe id="iFrame" name="iframe" src=""></iframe> 

來源是通過URL輸入。我需要更改此iFrame內的文本大小。 iFrame和源網址都在同一個域中。我試過這個:

function setFontSize(fontsize) { 
    $('iFrame').contents().css('font-size', '5px'); 
    alert("i am here"); 
} 

and this 


function setFontSize(fontsize) { 
    $("#iFrame").css("font-size","5px"); 
} 

都似乎不起作用。這裏

#site.html 
<iframe id="iFrame" name="iframe" src="iframe.html"></iframe> 
<script type="text/javascript"> 
;(function($) { 
     $(function() { 
      var iframe = top.frames['iframe'].document; 
      $('p', iframe).css('font-size','5px'); 
     }); 
})(jQuery); 
</script> 

#iframe.html 
<p>some test content</p> 


的線索是,它不會在桌面上工作:

+0

是在同一個域中你的I幀頁? – 2012-02-08 18:57:48

+0

@ Diodeus-是的。 – NoviceMe 2012-02-08 18:59:46

回答

1

試試這個。你需要在你的服務器上測試它。 如果您將兩個文件複製到/path/to/your/server/root/test並查看http://localhost/test您將看到結果。
還有一件事:使用iframes是一個非常嚴格的任務,兩個站點(父和iframe)需要位於同一臺服務器(相同的協議,主機,端口)上。

0

試試這個

$(document.getElementById('IFrameName').contentWindow.document.body).find('font').attr("face", "Tahoma")