473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Loading a Random html file in an iframe

2
Having no experience with JavaScript, what I need to do is randomly select a page from a directory of 500 html files sequentially named file001.html up to file500.html, and have it load in an iframe on an existing page.

I've come across a lot of scripts that will do this with images, or ones that you have to specify the files to be loaded in array, but isn't there a way to just randomly do this with html files?

Thanks,
Aug 21 '07 #1
2 3108
epots9
1,351 Expert 1GB
give this a shot:
Expand|Select|Wrap|Line Numbers
  1. //random number from and including 1 - 500
  2. var num = Math.floor(Math.random() * 500) + 1;
  3.  
  4. ifram.src="file" + num +".html";
  5.  
u'll need to add more,
good luck
Aug 21 '07 #2
gaszer
2
Hey, thanks for your very speedy response. After jacking around with it, I modified the script from Dynamic Drive, inserted your suggestion, and got the following Frankenstein that seems to work.

Don't know if I need all of it, but it's working so I'm not going to mess around with it:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript1.2">
  2.  
  3. var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
  4. var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1
  5.  
  6. //Specify IFRAME display attributes
  7. var iframeprops='width=170 height=210 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'
  8.  
  9. //Specify number of random files to pick from to display inside iframe
  10. var num = Math.floor(Math.random() * 12) + 1;
  11.  
  12. if (ie||dom)
  13. document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')
  14.  
  15. function random_iframe(){
  16. if (ie||dom){
  17. var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
  18. iframeobj.src="FILENAME" + num +".html"
  19. }
  20. }
  21.  
  22. window.onload=random_iframe
  23.  
  24. </script>
(Just testing with 12 files)
Aug 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: StumpY | last post by:
Hi I have a code which works ok, except I would like to load the specified file in an inline frame (I1) on the page instead of a whole new page if at all possible - any help appreciated! Here is...
1
by: Mel | last post by:
how can i wait for one iframe to completely load before loading a second one ? thanks for your help
6
by: fniyogi | last post by:
Does anyone know how to suppress the "busy"/hourglass cursor that appears when a frame/iframe is loading, as in the g() functon below: <SCRIPT> function g() { if ( Math.floor(Math.random()*2)...
2
by: Helen | last post by:
Guys and gals, I am having a problem with an IFRAME that is embedded into an ASPX page (ASP.NET application). The IFRAME is originally empty (src=''). When a user selects a date from the...
10
by: Simon | last post by:
Hi, Sorry for the cross posting, but I think it applies to both languages. As we all know, JavaScript is client side and php is server side, (the php code is 'allowed' to do stuff on the...
3
by: Asterbing | last post by:
Since the "on fly addition..." thread has taken another direction, I'm opening a new one to be more explicit and recenter the subject. Well, the subject is to detect when a document is well...
5
by: Tudor Tihan | last post by:
Hi, This is my first post here, so please be kind. I have tryed to make a javascript html page loader by using an invisible <IFrame> and some javascript variable text passing between...
2
by: www.gerardvignes.com | last post by:
I am using this to load the client JavaScript for a web application when it is selected by the user) via an Ajax connection to the server. I have found only two ways of loading new JavaScript...
2
by: Mani | last post by:
I have a file browse dialog and an IFRAME on my web page. User will select an RTF file using the file browse dialog and I need to load the contents of that file in IFRAME so that the user could...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.