Reputation: 11
`Goal: I have a text file which consists of list of URLs separated by '\n'. My goal is to pass them into an array and load them sequentially after a page gets loaded.
My code:
<html>
<head> </head>
<script type="text/javascript">
var allText =[];
var allTextLines = [];
var Lines = [];
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "URL.txt", true);
var i=0;
txtFile.onreadystatechange = function URL()
{
if (txtFile.readyState == 4)
{
allText = txtFile.responseText;
allTextLines = allText.split(/\r\n|\n/);
document.write(allText);
window.location.href=allTextLines[i++];
window.onload=setTimeout(URL,1000);
}
}
txtFile.send(null);
</script>
</html>
I tried for loop. But, the browser keeps stuck in processing.
Any insights on how to do it?
Any help will be greatly appreciated.
Thanks.
Upvotes: 0
Views: 123
Reputation: 4760
If the new urls are on the same domain you could use the new html5 pushState method. https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Example
Upvotes: 0
Reputation: 2951
As soon as you change the location using window.location.href
the rest of the javascript you write will be ignored - and the javascript within the new location will be run (if any). If you wanted to do this you'd need to use an <iframe>
so that you can control the location without losing control of the window.
Upvotes: 2