$(document).ready(function() {
CreateIframe();//創(chuàng)建iframe
var doc = document.getElementById('ContentFrame').contentDocument.document;
});
function changeStyle()//修改動態(tài)創(chuàng)建的iframe的一些樣式
{
var x=document.getElementById("ContentFrame");
var y=(x.contentWindow || x.contentDocument);
if (y.document)y=y.document;
y.body.style.backgroundColor = "#f9f9f9";
y.body.style.padding = "0px";
y.body.style.margin = "10px";
y.body.style.fontSize = "small";
y.body.style.maxWidth = "100%";
}
///創(chuàng)建iframe 的方法
function CreateIframe() {
var iframe = document.createElement("iframe");
iframe.src = "Content.aspx?id="+$("#txid").val();//根據(jù)相應(yīng)的id 在頁面中顯示需要的內(nèi)容
iframe.setAttribute("id", "ContentFrame");
iframe.setAttribute("width", "100%");
iframe.setAttribute("height", "100%");
iframe.setAttribute("scrolling", "auto");
iframe.setAttribute("frameborder", "0");
if (iframe.attachEvent) {
iframe.attachEvent("onload", function() {
changeStyle();
});
} else {
iframe.onload = function() {
//? ? ? ? ? ? ? ? ? ? ? ? alert("Local iframe is now loaded.");
changeStyle();
};
}
</script>
兩段script都是百度后修改成自己要的