#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    65
    Rep Power
    12

    javascript document.title if/then?


    I'm using the following to print out the document title of a webpage:
    <script language="JavaScript">
    document.write (document.title)
    </script> Article

    What I'd like to do is find out if the title contains the word "collection" and if it does,
    have the word Articles (plural) print instead of just Article (singular).

    How would I a) find out if the title contains the word Collection and
    b) write the if/then to print out appropriate form of the word Article?

    Thanks for any help you can offer.
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Maybe...

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Excellent</title>
    </head>
    <body>
    <script type="text/javascript" language="JavaScript">

    var t = document.title;
    document.write (t + ' ');
    document.write((t.toLowerCase().indexOf('collection') == -1) ? 'Article' : 'Articles');

    </script>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    65
    Rep Power
    12

    Thanks


    Awesome - thanks! That does exactly what I needed!

IMN logo majestic logo threadwatch logo seochat tools logo