iframe 元素会创建包含另外一个文档的内联框架(即行内框架)。注意:在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素。
1.获取iframe的自适应大小,即:不适用height和width属性,而是用οnlοad="SetWinHeight(this);IFrameReSizeWidth(this)"方法
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;
}
}
}
}
2.在iframe页面中用js操作父窗口的内容
window.parent.document.getElementById('mulufirst').innerHTML=$(this).text();
3.iframe中的链接在父窗口中不出现”画中画“,即如何操作它的类似于target的属性:在location前加上window.top/parent/blank.....等,如果是单纯的标签,直接设置target属性即可;
$(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";
}
});
如果需要设成_blank属性的话,不能直接用window.blank.location.href
window.top.location.href = "http://baidu.com";
window.open("http://baidu.com","_blank");