get full html source code of page through ajax request through javascript

前端 未结 1 593
天涯浪人
天涯浪人 2021-01-21 09:31

The javascript code will be launched from www.example.com through the url bar in google chrome so i cannot make use of jquery. My goal is to pass the full html source code of ww

相关标签:
1条回答
  • 2021-01-21 10:18
    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);

    then i host the js file on my computer.. i use analogx simpleserver... then you can use a full page for your script

    0 讨论(0)
提交回复
热议问题