Connecting Tech Pros Worldwide Help | Site Map

Javascipt - Array- Iframe -Refresh

Seven
Guest
 
Posts: n/a
#1: Feb 9 '06
Can someone direct me, or give me advice...

I simply would like to load a random html page from an array into an
iframe upon refresh or visit. Every time the user visits the site a
diferent news article (html page) will present itself in the iFrame.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Feb 10 '06

re: Javascipt - Array- Iframe -Refresh


Seven wrote:
[color=blue]
> I simply would like to load a random html page from an array into an
> iframe upon refresh or visit. Every time the user visits the site a
> diferent news article (html page) will present itself in the iFrame.[/color]

Including random content is a FAQ here. Please do a minimum of research
on previous articles before you post. <URL:http://jibbering.com/faq/>

FWIW: Include something like the following in the `body' element of your
HTML document.

<script type="text/javascript">
var
a = ["b", "c", "d"],
rnd = Math.floor(Math.random() * a.length),
url = a[rnd];

document.write([
'<iframe src="' + url + '" ...>',
' <a href="' + url + '">Go to article #' + rnd + '<\/a>',
'<\/iframe>'
].join("\n"));
</script>

Note that if you really want to use this client-side scripting instead of
the server-side scripting recommended here, users without client-side
script support will not see anything.


HTH

PointedEars
Seven
Guest
 
Posts: n/a
#3: Feb 11 '06

re: Javascipt - Array- Iframe -Refresh


Exactly what I was looking for. Thank you!!

Closed Thread