free hosting   image hosting   hosting reseller   online album   e-shop   famous people 
Free Website Templates
Free Installer

Random Popup Windows


This script lets you create a series of random popup windows.

A random URL is selected and displayed on page load, or when the page is refreshed.


Compatability

Should work OK in all browsers - no problems with IE 5 or NS 6.1.


Paste the following code in your head section of your page:
And add this to your body tag:

How It Works

The desired number of URLs are placed in an array, newurl:
var newurl=new Array()

newurl[0]="url 1"
newurl[1]="url 2"
newurl[2]="url 3"
newurl[3]="url 4"
newurl[4]="url 5"
The URLs can be local pages on your site - eg: mypage.html

Or links to other sites - eg: http://www.yahoo.com.

You can have as many URLs as you like - just add extra array items at the bottom.


The function randompopup() is called on page load:
var mylocation=newurl[Math.floor(Math.random()*newurl.length)]
This randomly chooses a number whose limits are the length of the array, newurl.length.

In this example, there are 5 URLs, hence the numbers possible are 0, 1, 2, 3 and 4.

The URL whose number is selected is then assigned to the variable mylocation.

For example, if 3 is selected:
mylocation=newurl[3]
Referring to the script section above, you'll see that the contents of newurl[3] is URL 4.


This value is now passed to the popup generator section:
  • a customised popup window is created
  • the chosen URL is loaded into the popup

  • For details of how to create customisable popup windows, see Creating A Popup Window.


    Try It Out

    Refresh this page a few times.

    You'll see that the contents of the popup change each time.



    © 2002 CyberSchool
    Last Update: