How to get WHOLE content of iframe?

后端 未结 4 2039
余生分开走
余生分开走 2021-01-05 07:36

I need to get whole content of iframe from the same domain. Whole content means that I want everything starting from (including), not only &l

4条回答
  •  不思量自难忘°
    2021-01-05 08:06

    You can get the literal source of any file on the same domain with Ajax, which does not render the html first-

    //

    function fetchSource(url, callback){
    
        try{
            var O= new XMLHttpRequest;
            O.open("GET", url, true);
            O.onreadystatechange= function(){
                if(O.readyState== 4 && O.status== 200){
                    callback(O.responseText);
                }
            };
            O.send(null);
        }
        catch(er){}
        return url;
    }
    function printSourceCode(text){
        var el= document.createElement('textarea');
        el.cols= '80';
        el.rows= '20';
        el.value= text;
        document.body.appendChild(el);
        el.focus();
    }
    

    fetchSource(location.href, printSourceCode);

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题