在 index.html 中的代码如下:
01 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
02 | < html xmlns = "http://www.w3.org/1999/xhtml" > |
03 | < head > |
04 | < title >iframe tag test</ title > |
05 | < style type = "text/css" > |
06 | html, body |
07 | { |
08 | margin: 0px 0px; |
09 | width: 100%; |
10 | height: 100%; |
11 | } |
12 | iframe |
13 | { |
14 | margin: 0px 0px; |
15 | width: 100%; |
16 | height: 100%; |
17 | } |
18 | </ style > |
19 |
20 | < script type = "text/javascript" > |
21 | function iframeHeight() { |
22 | document.getElementById('iframeId').height="100%"; |
23 | } |
24 | </ script > |
25 |
26 | </ head > |
27 | < body > |
28 | < iframe id = "iframeId" frameborder = 0 scrolling = no |
29 | src = http ://www.google.com /> |
30 | </ body > |
31 | </ html > |
在上述代码中,样式代码部分明确指出了 html, body 的 width 和 height 为 100%,这是必须的,随后指出了 iframe 的 width 和 height 也为 100%,这里的意思是说 iframe 的 width 和 height 是相对于其父容器的 width 和 height 为 100%,这样的方法既简单又明了,IE、Firefox(火狐浏览器)、chrome(Google浏览器)均能顺利通过。希望遇到此问题的同志不要再 走弯路!
转自:http://blog.baiwand.com/?post=3