动态生成iframe

window.onload=function(){ 
        
var iframe = document.createElement("iframe");
        iframe.id 
= "ID_Iframe"
        iframe.src 
= "about:blank";
        document.body.appendChild(iframe);  
        
var  html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
             html
+='<html xmlns="http://www.w3.org/1999/xhtml">\n';
             html
+='<head>\n';
             html
+='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n';
             html
+='<title>无标题文档</title>\n';
             html
+='</head>\n';
             html
+='<body>\n';
             html
+='<label id="jueban">lixi</label>\n';
             html
+='</body>\n';
             html
+='</html>\n';
        
var doc;
        
if(!document.all){
            doc 
= iframe.contentWindow.document;              
        }
else{
            doc 
= window.frames["ID_Iframe"].document;            
        }       
        doc.open();
        doc.write(html);
        doc.close();
      };

posted on 2007-11-12 22:56  jueban's space  阅读(999)  评论(2编辑  收藏  举报

导航