iframe 元素会创建包含另外一个文档的内联框架(即行内框架)。注意:在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素。
<div id="iframepage"> <iframe src="/test/common.html" align="middle" id="iframepage" width="100%" height="435" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" ></iframe> </div>
1.获取iframe的自适应大小,即:不适用height和width属性,而是用onload="SetWinHeight(this);IFrameReSizeWidth(this)"方法
<script type="text/javascript"> function SetWinHeight(obj) { var win=obj; if (document.getElementById("iframepage")) { if (win && !window.opera) { if (win.contentDocument && win.contentDocument.body.offsetHeight) { win.height = win.contentDocument.body.offsetHeight + 25; } else if(win.Document && win.Document.body.scrollHeight) { win.height = win.Document.body.scrollHeight + 25; } } } } function IFrameReSizeWidth(obj) { var win=obj; if (document.getElementById("iframepage")) { if (win && !window.opera) { if (win.contentDocument && win.contentDocument.body.offsetWidth) { win.width = win.contentDocument.body.offsetWidth; } else if(win.Document && win.Document.body.scrollWidth) { win.width = win.Document.body.scrollWidth; } } } } </script>
2.在iframe页面中用js操作父窗口的内容
window.parent.document.getElementById(‘mulufirst‘).innerHTML=$(this).text();
3.iframe中的链接在父窗口中不出现”画中画“,即如何操作它的类似于target的属性:在location前加上window.top/parent/blank.....等,如果是单纯的<a>标签,直接设置target属性即可;
<a class="search_btn" id="searchAnswer">搜索答案</a>
<script> $(function() { var searchKey = $("#searchAsk"); $("#searchAnswer") .click( function() { if (searchKey.val() == "" || searchKey.val() == "请输入你的问题?") { window.top.location.href = "http://baidu.com"; } else { var asktitle = escape(searchKey.val()); window.top.location.href = "http://hao123.com?key=121"; } }); </script>
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-05 21:40:44