Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-14-2012, 07:12 AM   PM User | #1
sharathvn43
New to the CF scene

 
Join Date: May 2012
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
sharathvn43 is an unknown quantity at this point
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>
sharathvn43 is offline   Reply With Quote
Old 05-14-2012, 07:25 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
sharathvn43 (05-15-2012)
Old 05-14-2012, 02:32 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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?
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
sharathvn43 (05-15-2012)
Old 05-15-2012, 10:09 PM   PM User | #4
sharathvn43
New to the CF scene

 
Join Date: May 2012
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
sharathvn43 is an unknown quantity at this point
I think that xelawho is right.
Is there any other way to do it????
sharathvn43 is offline   Reply With Quote
Old 05-15-2012, 10:27 PM   PM User | #5
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
Try using an iframe to load the text files in
Lerura is offline   Reply With Quote
Users who have thanked Lerura for this post:
sharathvn43 (05-16-2012)
Old 05-17-2012, 06:53 PM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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...
xelawho is offline   Reply With Quote
Old 05-17-2012, 07:39 PM   PM User | #7
sharathvn43
New to the CF scene

 
Join Date: May 2012
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
sharathvn43 is an unknown quantity at this point
The point is automatically open several websites through a browser we've instrumented which prints stack trace, ASTs which addresses our research questions
sharathvn43 is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, redirect

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:12 AM.


Advertisement
Log in to turn off these ads.