1.iframe的语法格式:
<iframe src="your page's url" width="100" height="100"></iframe>
切不可写成:
<iframe src="your page's url" width="100" height="100"/>
这样会破坏html的网页结构,出现预想不到的结果
2.无边框效果:
<iframe src="you page's url" width="750" height="30" frameborder="no" border="0" marginwidth="0" marginheight="0"scrolling="no" allowtransparency="yes"></iframe>
或
<iframe src="you page's url" width="750" height="30" frameborder="0" scrolling="no"></iframe>
3.高度自适应:
方法一(较简单):
<IFRAME id=headlogin marginWidth=0 marginHeight=0 src="xxx" frameBorder=0 width=100% scrolling=no height=25 οnlοad="this.height=this.contentWindow.document.body.scrollHeight"></IFRAME>
方法二(较通用):
<script language="Javascript"> var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1] //extra height in px to add to iframe in FireFox 1.0+ browsers var FFextraHeight=getFFVersion>=0.1? 16 : 0 function dyniframesize(iframename) { var pTar = null; if (document.getElementById){ pTar = document.getElementById(iframename); } else{ eval('pTar = ' + iframename + ';'); } if (pTar && !window.opera){ //begin resizing iframe pTar.style.display="block" if(pTar.contentDocument&&pTar.contentDocument.body.offsetHeigh{ //ns6 syntax pTar.height=pTar.contentDocument.body.offsetHeight+FFextraHeigh; } else if (pTar.Document && pTar.Document.body.scrollHeight){ //ie5+ syntax pTar.height = pTar.Document.body.scrollHeight; } } } </script>
<iframe id="myTestFrameID" οnlοad="javascript:{dyniframesize('myTestFrameID');}" marginwidth=0 marginheight=0 frameborder=0 scrolling=no src="/myiframesrc.php" width=200 height=100></iframe>
4.iframe标签中页面调用包含此iframe标签页面中的js函数:
假设包含iframe标签的页面中有名为killUpdate('')的方法,在iframe标签中的页面中可以如此调用:
window.parent.killUpdate('');
5.判断iframe内容是否加载成功
var iframe = document.getElementById('view'); if (iframe.attachEvent){ iframe.attachEvent("onload", function(){ alert('iframe加载成功!'); });} else { iframe.onload = function(){ alert('iframe加载成功!'); }; }