SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to download objects from other websites

    Hi, I have a problem, say that I have a lot of diffrent websites, and that those are on diffrent webservers, now also say that I want one specific objekt on all those websites, is it possible to write a javascript that gets that object from another webserver?

    Code:
    function getElementFromAnotherSite(){
    
    /*Download www.example.com/images/example.gif
    *Put it in the folder ../images/example.gif on current webserver
    *document.getElementById('id_where_i_want_to_display_the_picture').background-image: url(../images/example.gif);
    */
    
    }
    I am gonna move files around alot between diffrent servers, so no file are going to be static on a webserver, thats why I want to download it on the current webserver using the file.

    Is this possible in javascript? Or can this be achieved in another language?

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I simply want a script that can move around files between my webservers, depending on what webb url that your'e on. I know that this can't be done when it comes to server-local client, but can this be done between server-server?

    Thanks

  3. #3
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    JavaScript is client side, and this JavaScript can be executed only on client computer, not on server. But JavaScript can initiate process on server by creating request to it.

    For example AJAX. You call it, then server side app download file to it and return data about file trough response.

    I hope this helps.
    http://www.wiseblog.info
    Programmers don't die, they just GO SUB without return.

  4. #4
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, it got me in the right direction. I see on the

    w3shools homepage that they get a .txt file, does this work for all kind of objects? Html files, images etc?

    What if you want multiple files, do you have to do the "get" command sevral times like this

    Code:
    xmlhttp.open("GET","ajax_info.txt",true);
    xmlhttp.open("GET","documents/test_info.html",true);
    xmlhttp.open("GET","images/test_info.gif",true);
    How do you then save these files on the server?

    For example I do this

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","http://tdsoft.se/hej.txt",true);
    xmlhttp.send();
    /*Here I want to store this file on another server, for example
    *http://hulenet.se/data/hej.txt" /*Assume that I have write access to this server*/
    */
    }
    </script>
    </head>
    <body>
    
    <div id="myDiv"><h2>Want to download hej.txt</h2></div>
    <button type="button" onclick="loadXMLDoc()">Change Content</button>
    
    </body>
    </html>
    Another quastion


    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

    the above is to show text inside an element with id "mydiv", if I would like to change the background, for example change the background-image to this picture "http://images.povcomp.com/entries/images/480/161_main.jpg", what is the syntax for this?

    Thanks you so much

  5. #5
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    you can initiate action on server, and script that action to download list of files and it can return it to you with coma separated values so you can manipulate them

    but in order to change background image of element you can do it like this

    document.body.background = 'http://images.povcomp.com/entries/images/480/161_main.jpg';
    http://www.wiseblog.info
    Programmers don't die, they just GO SUB without return.

  6. #6
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okej, so can anybody please give me an example on how this can be done?

    Say i want to copy the files tdsoft.se/images/example.gif and tdsoft.se/data/test.html.

    And write them to hulenet.se/data and hulenet.se/images?

    Would be very appreciated

    Where do I begin, seems like the one below only could find text files.

    Thanks again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •