日期:2014-05-16  浏览次数:20351 次

怎么用JS获得HTML页的全部代码
怎么用JS获得HTML页的全部代码 不可以改变原HTML代码的格式
求高手解决

------解决方案--------------------
Ajax申请当前页。
------解决方案--------------------
仅限IE
document.getElementsByTagName("html")[0].outerHTML
------解决方案--------------------
outerHTML得到的跟原来的可能会有点出入。
HTML code

<!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>DocTitle</title>
<script language="javascript" src="lib.js"></script>
<script>
function getXHR(){
    var xhr = 0;
    try{
        xhr = new XMLHttpRequest()
    }catch(err1){
        try{
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
        }catch(err2){
            try{xhr = new ActiveXObject('Msxml2.XMLHTTP')}catch(err3){};
        }
    };
    return xhr;
};
var xhr = getXHR();
if(!xhr){alert('您的浏览器版本过低,不支持XMLHttpRequest,请升级浏览器!');};
var url = location.href;
xhr.onreadystatechange = stateChanged;
xhr.open("GET",url,true);
xhr.send(null);
function stateChanged(){
    if (xhr.readyState==4)alert(xhr.responseText);
};
</script>
</head>

<body class="aa">
test...
</body>
</html>

------解决方案--------------------
http://topic.csdn.net/u/20100526/16/7f5d93c2-d9df-437c-8805-02230b7a9613.html?26951

这里有很多你要的答案
------解决方案--------------------
document.outerHTML
------解决方案--------------------
function OpenShowContentPnpWin(_Url ,_title)
{
$.blockUI();
$.ajax( 

url:_Url,
dataType: 'html',
cache:false, 
success:function(data) 
{
$.unblockUI();

$('#webengine_dialog_Model').remove();

//创建model窗口
$("body").append('<div id="webengine_dialog_Model" title="'+_title+'" style="overflow:auto"></div>');

$("#webengine_dialog_Model").dialog({
autoOpen: false,
bgiframe: true,
modal: true
});

$("#webengine_dialog_Model").html(data); 

SetInputStyle();

$("#webengine_dialog_Model").dialog('open');
var _height_model = $(".queryspace_div").height()+60;
var _width_model = $(".queryspace_div").width()+30;
self.parent.Setheightofmodel(_height_model+100);
//alert('_height_model='+_height_model+";_width_model="+_width_model );

$('#webengine_dialog_Model').dialog('option', 'width', _width_model);
$('#webengine_dialog_Model').dialog('option', 'height', _height_model);

$('#webengine_dialog_Model').dialog('option', 'position', 'center');

}
}); 

}