1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HTML to string JS

Discussion in 'HTML & JavaScript' started by Shoop, May 7, 2015.

  1. Shoop

    Shoop Newbie

    Joined:
    Apr 22, 2015
    Messages:
    1
    Likes Received:
    0
    Heya all, so ive run into a problem with my scripting knowledge.
    I need some help with turning a website into an html. to be more specific, im wondering how to give URL to the script and that it turns the website from the URL into a string. as im a bit new in JS, im having a hard time understanding XMLHttpRequest and how to execute it compleatly. Ive found and read some examples but they are all outdated and dont work. and reading up on url-that-i-cant-post is bit hard o me cos i dont understand much of it.


    to give a more specific problem, i need to input an URL and save the html in a string. later i can, and know how to, extract the data that i need from it, but im stuck on the problem of saving it as a string.

    using win8.1 and FF, other OS-es are not an option, and i would prefer to keep using FF
    If you do have any queestions feel free to ask, ill try to respond asap

    regards,
    Shoop
     
  2. BTSTU

    BTSTU Newbie

    Joined:
    May 17, 2015
    Messages:
    14
    Likes Received:
    1
    Code:
    
    document.getElementsByTagName('html')[0].innerHTML
    
    
    Instead of the document object, you use the variable where you put the response of your http request.

    So if you did this:

    Code:
    
    function getWebsite(url)
    {
         var xmlHttp = new XMLHttpRequest();
         xmlHttp.open( "Get", url, false ); // Uses GET to download the website. 
         xmlHttp.send( null );
        return xmlHttp.responseText;
    }
    
    var website = getWebsite('url');
    website.
    This would be easier in PHP though and faster imo. Javascript uses the client to process stuff like this. So processing speed will depend on the client. If you grabbed the info with Js then pushed it to PHP, the php does all the processing.

    Also having it process information on the client side opens your site up to alot of exploits.
     
    • Thanks Thanks x 1
    Last edited: May 17, 2015
  3. member8200

    member8200 Regular Member

    Joined:
    Aug 9, 2014
    Messages:
    470
    Likes Received:
    33

    http://www.accessify.com/tools-and-wizards/developer-tools/html-javascript-convertor/
    This is a free converter :)
     
  4. Hexiuss

    Hexiuss Junior Member

    Joined:
    Aug 18, 2010
    Messages:
    108
    Likes Received:
    14
    I know this was posted awhile ago, but I just wanted to say that function '''' getWebsite(url) ''' is super cool. I didn't know that object existed.