简体   繁体   English

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

[英]get full html source code of page through ajax request through javascript

The javascript code will be launched from www.example.com through the url bar in google chrome so i cannot make use of jquery. javascript代码将通过google chrome中的url栏从www.example.com启动,因此我无法使用jquery。 My goal is to pass the full html source code of www.example.com/page.html to a variable in javascript when i launch the code in www.example.com. 我的目标是在www.example.com上启动代码时,将www.example.com/page.html的完整html源代码传递给javascript中的变量。 Is this possible? 这可能吗? If so how? 如果是这样的话? I know to get the current page source it's just document.documentElement.outerHTML but i'm not sure how i'd do this. 我知道要获取当前页面源它只是document.documentElement.outerHTML但我不知道我该怎么做。 I think it's possible by using responseText somewhere in the following code: 我认为通过在以下代码中的某处使用responseText是可能的:

http.send(params);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://www.example.com/page.html",true);
xmlhttp.send();
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();
}

this is how i run script from the address bar.. I do it all the time.. i create a bookmark like this javascript:script=document.createElement('script');script.src='http://10.0.0.11/clear.js';document.getElementsByTagName('head')[0].appendChild(script); void(sss=1); 这就是我从地址栏运行脚本的方式..我一直这样做..我创建一个像这样的书签javascript:script=document.createElement('script');script.src='http://10.0.0.11/clear.js';document.getElementsByTagName('head')[0].appendChild(script); void(sss=1); javascript:script=document.createElement('script');script.src='http://10.0.0.11/clear.js';document.getElementsByTagName('head')[0].appendChild(script); void(sss=1);

then i host the js file on my computer.. i use analogx simpleserver... then you can use a full page for your script 然后我在我的电脑上托管js文件..我使用analogx simpleserver ...然后你可以使用整页的脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM