Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to load random links from a txt or doc file?

Status
Not open for further replies.

RTrinidad

Technical User
Apr 6, 2008
1
Hi i wanted to know how can i be able to load differente weblinks from a txt or doc file lets say i have a web opend and part of my script runs an acction and after that action i want the page to refresh after 5 seconds and load a different page from a file. Is this possible?
 
You can load the data to be displayed into an array. Then you can generate a random number between 0 and the number of items in the array (less one, zero based indexes). Use that random number as the index to the array... providing you with a random selection. You can set a timer to refresh the page (using setTimeout() if you wish).

The hurdle is the data. Javascript doesn't do well reading from an arbitrary text file. If you store the data in a .js file (represented as a pre-populated array) then your task is much more straightforward.

Let us know how you go.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
[ ]
If you have static items, you can do like I do with the following code. As noted above, you may have problems with dynamic items that you are uploading, but if you can upload them, you can use a variation of this code that I use on my eBay pages.

Code:
function Writedefaultblurb(){
	var text = new Array(1);
	text[0] = 7;
	text[1] = "Test one";
	text[2] = "Test two";
	text[3] = "Test three";
	text[4] = "Test four";
	text[5] = "Test five";
	text[6] = "Test six";
	text[7] = "";

	ztext = text[Getrandommod(text[0])];

	if (ztext != ""){
		d.writeln("<CENTER>");
		d.writeln("<TABLE BORDER='3'  BGCOLOR='lightblue' CELLPADDING='6' WIDTH='95%'>");
		d.writeln("<TR>");
		d.writeln("<TD><FONT FACE='arial, geneva, verdana, helvetica'>");
		d.writeln("<CENTER>");
		d.writeln("<FONT SIZE='+0'><FONT COLOR=" + linkcolor + "><B>" + ztext + "</B></FONT></FONT>");
		d.writeln("</CENTER>");
		d.writeln("</TD>");
		d.writeln("</TR></TABLE>");
		d.writeln("</CENTER>");
	}
}

function Getrandommod(dv){
	zz = new Date();
	zz = Math.floor(zz.getTime()/1000);
	zz = zz % dv + 1;
	return zz;
}

mmerlinn


"Political correctness is the BADGE of a COWARD!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top