2012-02-08 74 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")