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

解决方案 »

  1.   

    Lz try...<!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=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript"><!--
    function test(){
      var $t = document.getElementById("test")
      alert($t.innerHTML);
    }
    //--></script>
    </head><body>
    <div id="test" onclick="test();">
    <div style="font-size:14px; color:#ccc">点我</div>
    </div>
    </body>
    </html>
      

  2.   

    仅限IE
    document.getElementsByTagName("html")[0].outerHTML
      

  3.   

    outerHTML得到的跟原来的可能会有点出入。<!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>
      

  4.   

    不需要自己做的,用firebug,打开脚本与网络功能,打开网页时相关的所有文件都能看到。
      

  5.   

    tableElement.outerHTML;
    FF下:  
    new XMLSerializer().serializeToString(tableElement);
    onclick=location.replace( "view-source: "+location)
      

  6.   

    http://topic.csdn.net/u/20100526/16/7f5d93c2-d9df-437c-8805-02230b7a9613.html?26951这里有很多你要的答案
      

  7.   

    难道是获得JS所在页面自身吗?一般来说,还是取具体内容,利用DOM结构去一级级取,整体取整个代码,自己输出自己,这个很少具有实际意义的。楼主问问题时最好说清要实现的大目标,利于别人能为你提供更好的实现方式。
      

  8.   

    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');
               
            }
        }); 
        
      

  9.   

    document.doctype.nextSibling.outerHTML