Jump to content

A script that visits pages


aggixx
 Share

Recommended Posts

Im trying to make a script where you can input a list of URLs and when you hit go, it visits each page for 30 seconds.I haven't been doing js for a while, so I cant remember exactly what some of the functions are and how they work.This is what I have so far:

<html><head><title>PTC Machine</title><script>function run() {sites=document.form.ta.value}</script></head><body><div name=div><center><script src="http://gmodules.com/ig/ifr?url=http://linkleecher.com/linkleecher.xml&up_url=Please%20Enter%20Website&up_onefilter=.php?ad=&up_output=text&synd=open&w=320&h=110&title=Link+Leecher&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js"></script><br><br>Please paste the list of links in the box below and hit go.<br><br><form name=form><textarea name=ta cols=50 rows=13></textarea><br><br><input type=button name=init value='	   Go	   ' onclick=run></form></center></div></body></html>

I know theres a function that lets you split variables. If I could use that to split it into a variable for every url. At this point, I have no idea how to make it visit the pages one by one. The reason the div is in there is so that you can change the contains of the div to a frame for each page.The external script in there is something used to generate a list of links, thats not really relevant currently though.

Link to comment
Share on other sites

I'm afraid it's more than Javascript you're going to have to improve. Your HTML is invalid too.As much as I hate frames, that's the only way you're going to be able to open a website without stopping your script from running.I'm not going to make the script for you. I'll just tell you how it can be done and you can program it yourself. If you don't know all the Javascript functions, that's what the W3Schools tutorial and reference are for.Just split the string (function split() in the W3Schools reference) by line breaks (\n) to get an array of URLs, and then use setTimeout or setInterval to load each of the URLs into the frame every 30 seconds.

Link to comment
Share on other sites

Great, thats what I was hoping to hear. Thanks, Ill look up those functions and try to implement them.Edit: Ok, Im not exactly sure how to put each individual value in an array through the same process. Can someone give me a quick snippet of code, to show me?

Link to comment
Share on other sites

Well, you could open the first URL in a new window and change the other window's URL every 30 seconds... That's not a whole lot different from a frame, but it might be better for its simplicity of layout.EDIT: To put a random number from 1 to 10 in each slot of the array arr...

var arr = [];for(var i = 0; i < arr.length; i++){	arr[i] = Math.ceil(Math.random() * 10);// Don't worry about the Math functions; they're just details of the example.}

Link to comment
Share on other sites

Well, you could open the first URL in a new window and change the other window's URL every 30 seconds... That's not a whole lot different from a frame, but it might be better for its simplicity of layout.
That would be good, although I have no clue how to do that. Can you just tell me how to put each value in a array through the same process/function?
Link to comment
Share on other sites

Im not sure I understand that. This is what I want it to do to each url, which I've already split into an array

document.form.div.innerHTML="<iframe src=" + splited + " height=100% width=100%></iframe>"setTimeout("var none=1", 37000)

PS splited is the name of the array

Link to comment
Share on other sites

What part are you having trouble on? Assuming it's the for-loop, I'll break down the loop header...

for(	var i = 0;// executed once, just before the first run of the loop	i < arr.length;// boolean evaluated before each run, loop broken if false	i++// executed after each run, makes the boolean false when the last slot is reached){	arr[i] = "whatever you want, can be different each time like a method or a calculation";}

Or are you stumbling on the 0-based array system (which names the array slot one less than humans do for each position)?

Link to comment
Share on other sites

Well I don't know If Im doing this right but this is what I have so far:

<html><head><title>PTC Machine</title><script>function run() {var sites=document.form.ta.valuevar xsplited=sites.split("/n")for (x in splited){document.getelementbyid(div).innerHTML="<iframe src=" + splited + " height=100% width=100%></iframe>"setTimeout("var none=1", 37546)}}</script></head><body><form name=form><div id=div><center><script src="http://gmodules.com/ig/ifr?url=http://linkleecher.com/linkleecher.xml&up_url=Please%20Enter%20Website&up_onefilter=.php?ad=&up_output=text&synd=open&w=320&h=110&title=Link+Leecher&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js"></script><br><br>Please paste the list of links in the box below and hit go.<br><br><textarea name=ta cols=50 rows=13></textarea><br><br><input type=button name=init value='	   Go	   ' onclick=run()></center></div></form></body></html>

Link to comment
Share on other sites

First, I see some minor mistakes that will (or could, for the last one) break your code as it is:

  • document.getelementbyid is not a function; you're wanting document.getElementById.
  • "/n" is not a newline; you want "\n".
  • I don't think all systems will use "\n" in your textarea... When they're not communicating on the Internet, Mac uses "\r", Windows uses "\r\n", and Unix (Linux) uses "\n". I don't know whether they are consistent online.

Regarding your logic, you're very close, but I have a hunch that you aren't understanding the loops yet. Here's a while loop that does the same thing as the above for loop...

var i = 0;while(i < arr.length){	arr[i] = "whatever you want, can be different each time like a method or a calculation";	i++;}

This construct would be used so often that the for loop is worth putting in the language as sort of a shorthand. But the construct I used above is also pretty common, and the for-in loop is shorthand for it. Here's the basic for loop for what you want:

for(var i = 0; i < splited.length; i++){	document.getelementbyid(div).innerHTML="<iframe src=" + splited[i] + " height=100% width=100%></iframe>"	setTimeout("var none=1", 37546)}

Your for-in loop also needs a minor modification, because you are setting x equal to each successive slot in splited:

for (x in splited){	document.getelementbyid(div).innerHTML="<iframe src=" + x + " height=100% width=100%></iframe>"	setTimeout("var none=1", 37546)}

Link to comment
Share on other sites

I thought div was a variable.Put it within quotes, it's a string:document.getElementById("div")
Its working. Kind of.Ill upload it so you can see.Edit: Click Here (its bravehost so its not that good)Edit: There seems to be some really weird errors. It seems like it opens the last url, and the timing isnt working, it never changes.
Link to comment
Share on other sites

Your loop is just setting the innerHTML of the div to the iframe immediately. It's not setting the first one, then waiting, then setting the next one, it just sets them all (so the last one is the one you see). You need to use setTimeout to have it go through them. So the run function would parse up the list of URLs, and then call another function to load the URL. That function would use a counter so it knows which URL to load, and would use setTimeout to run itself again.

var splited = false;var nr = 0;function run() {  var sites=document.form.ta.value  splited=sites.split("\n")  nr = 0;  showpage();}function showpage(){  document.getElementById("div").innerHTML="<iframe src=" + splited[nr] + " height=65% width=100%></iframe>"  nr++;  if (nr < splited.length)	setTimeout("showpage()", 30000);}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...