您的位置:首页 > Web前端 > HTML

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

2012-02-14 09:26 609 查看
<!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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐