通过javascript获取完整的html源代码页面

时间:2013-07-25 02:21:39

标签: javascript ajax get

javascript代码将通过google chrome中的url栏从www.example.com启动,因此我无法使用jquery。我的目标是在www.example.com上启动代码时,将www.example.com/page.html的完整html源代码传递给javascript中的变量。这可能吗?如果是这样的话?我知道要获取当前页面源它只是document.documentElement.outerHTML但我不知道我是怎么做到的。我认为可以在以下代码中的某处使用responseText

http.send(params);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://www.example.com/page.html",true);
xmlhttp.send();

1 个答案:

答案 0 :(得分:0)

data = ""
url = "http://www.example.com/page.html"
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4){
    data = xhr.responseText
    }
}
xhr.send();

function process(){
    url = "http://www.example.com/page.html"
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4){
        alert(xhr.responseText)
        }
    }
    xhr.send();
}

这是我从地址栏运行脚本的方式..我一直这样做.. 我创建这样的书签 javascript:script=document.createElement('script');script.src='http://10.0.0.11/clear.js';document.getElementsByTagName('head')[0].appendChild(script); void(sss=1);

然后我在我的电脑上托管js文件..我使用analogx simpleserver ...然后你可以使用整个页面为你的脚本

相关问题