通过URL获取html代码实现页面嵌入(代替iframe效果)


 

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"   />
< title >通过URL获取html代码实现页面嵌入(代替iframe效果) </ title >
</ head >
< script  type ="text/javascript"  language ="javascript" >
    
function  getHtmlContentBySoap(url,showDivId){ debugger ;
    
if ( ! url || url == "" ){
        document.getElementById(showDivId).innerHTML
= "" ;
        
return ;
    }
    
if (window.XMLHttpRequest){
       req
= new  XMLHttpRequest();
    }
else   if (window.ActiveXObject){
       req
= new  ActiveXObject( " Microsoft.XMLHTTP " );
    }
    
if (req){
        req.open(
" GET " ,url, true );
        req.onreadystatechange
= function (){
            getHtmlContentBySoapCallBack(url,showDivId);            
       };
       req.send();
    }
}
function  getHtmlContentBySoapCallBack(url,showDivId){
    
if (req.readyState  ==   4 ){
        
if (req.status  ==   200 ){
            
if (document.getElementById(showDivId)){
                document.getElementById(showDivId).innerHTML
= req.responseText;
            }
        }
    }
}


</ script >

< body >
< input  type ="button"  onclick ="getHtmlContentBySoap('http://www.baidu.com','exp_div');"   style =" width:50px; height:25px;"  value ="click" />
< div  id ="exp_div"  style ="width:980px; text-align:center;" ></ div >

</ body >
</ html >

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM