Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry loading URLS sequentially from arrays

    I am trying to load some hundreds of urls from a local text file.
    I was able to load them into an array.
    I want to load them sequentially after certain time interval.
    The script works fine if I remove setinterval but without it only 1 url gets loaded. Is there any other way to load all urls automatically 1-by-1.

    Here is the code:

    <html>
    <head> </head>
    <script type="text/javascript">
    var allText =[];
    var allTextLines = [];
    var Lines = [];
    var txtFile = new XMLHttpRequest();
    //var i=0;
    txtFile.open("GET", "URL.txt", true);
    allText = txtFile.responseText;

    txtFile.onreadystatechange = function f()
    {
    if (txtFile.readyState == 4)
    {
    allText = txtFile.responseText;
    allTextLines = allText.split(/\r\n|\n/);//the urls are separated by /n
    document.write(allText);
    var i=Math.floor(Math.random()*100);
    window.location=allTextLines[i];
    setInterval(f(),5000);// trying to load after 5 sec.
    }
    else {
    //alert("Didn't work");
    }
    }
    txtFile.send(null);
    // <body onLoad="setInterval('f()', 30000)">

    /* function onLoad(URL){
    if(onLoad.loaded)
    window.setTimeout(f,0);
    else if (window.addEventListener)
    window.addEventListener("load",f,false);
    else if (window.attachEvent)
    window.attachEvent("onload",f);
    }
    onLoad.loaded=false;
    onLoad(function() { onLoad.loaded=true; }); */

    </script>

    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    document.write(allText);

    document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    sharathvn43 (05-15-2012)

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,772
    Thanks
    55
    Thanked 518 Times in 515 Posts
    I may be completely lost here, but it seems to me that if everything else is working, the first time this line:
    Code:
    window.location=allTextLines[i];
    is run, the page will redirect to another URL and the rest of the links will never be shown?

  • Users who have thanked xelawho for this post:

    sharathvn43 (05-15-2012)

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I think that xelawho is right.
    Is there any other way to do it????

  • #5
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    878
    Thanks
    0
    Thanked 114 Times in 113 Posts
    Try using an iframe to load the text files in

  • Users who have thanked Lerura for this post:

    sharathvn43 (05-16-2012)

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,772
    Thanks
    55
    Thanked 518 Times in 515 Posts
    is the point of this really to open 100 URLs, in 5 second intervals? it sounds like the most annoying thing you could ever do to a website visitor...

  • #7
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts
    The point is automatically open several websites through a browser we've instrumented which prints stack trace, ASTs which addresses our research questions


  •  

    Tags for this Thread

    Posting Permissions

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