SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random page title with html???

    how can i display a random title for my website? i know there is a way, and ive seen it done, but does anyone know how its done?

    thanks...

  2. #2
    SitePoint Zealot seanlivo81's Avatar
    Join Date
    Jun 2002
    Location
    Bundaberg, Australia
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Java should be able to do it. Try javascripts.com.

  3. #3
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanlivo81
    Java should be able to do it.
    You mean JavaScript.

    How about this:
    Code:
    ...
    <head>
    <script type="text/javascript">
    var titles = new Array(
        'one',
        'two',
        'three');
    
    var title = titles[parseInt(Math.random() * titles.length)];
    document.write('<title>' + title + '</title>');
    </script>
    </head>
    ...

  4. #4
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could do a server side solution using PHP:

    PHP Code:
    <html>
    <head>
    <title><?php

    $titles 
    = array();

    $titles[] = "Possible Title 1";
    $titles[] = "Possible Title 2";
    $titles[] = "Etc. Etc.";

    srand ((float) microtime() * 10000000); // Seed the random number generator

    echo $titles[array_rand($titles)]; // Pick a random item from the array and output it
    ?></title>
    </head>
    <body>
    </body>
    </html>
    This requires your web host to support PHP. Also, you will probably have to name your file with a .php extension.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks randem, that helped...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •