create a variable link

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asd987

    #1

    create a variable link

    Hi,

    I must begin to say that I'm rather new in wtiting and using JavaScript. Now
    I want to use JavaScript in a HTML-page. On the homepage is a link. Every
    time the homepage is displayed the link must point to another target. I want
    to realize this by having a lot of differet targetpages. The names of these
    pages are p1001.htm until p<nnnn>.htm. At this moment the last is p1153.htm,
    but the amount is increasing every day.
    I have a file named "counter.tx t" which contains one line with the string of
    the last targetpage, at his moment "1153".

    My idea is to have a JavaScript which:
    1. reads the file counter.txt to determine the last available page
    2. then takes at random one number between 1001 and 1153,
    3. sets the HREF-link to page p<random>.htm.

    I know it must be possible in JavaScript, but can anyone help me?

    Thanks,

    Susan


  • Mick White

    #2
    Re: create a variable link

    asd987 wrote:
    [color=blue]
    > Hi,
    >
    > I must begin to say that I'm rather new in wtiting and using JavaScript. Now
    > I want to use JavaScript in a HTML-page. On the homepage is a link. Every
    > time the homepage is displayed the link must point to another target. I want
    > to realize this by having a lot of differet targetpages. The names of these
    > pages are p1001.htm until p<nnnn>.htm. At this moment the last is p1153.htm,
    > but the amount is increasing every day.
    > I have a file named "counter.tx t" which contains one line with the string of
    > the last targetpage, at his moment "1153".
    >
    > My idea is to have a JavaScript which:
    > 1. reads the file counter.txt to determine the last available page
    > 2. then takes at random one number between 1001 and 1153,
    > 3. sets the HREF-link to page p<random>.htm.
    >
    > I know it must be possible in JavaScript, but can anyone help me?
    >
    > Thanks,
    >
    > Susan
    >[/color]
    Use an SSI to include "counter.tx t", format it something like the
    following:

    <p id="whatever" style="display: none">[number here]</p>


    <script type="text/JavaScript">
    var base=isNaN(docu ment.getElement ById("whatever" ).innerHTML)?""
    :+(document.get ElementById("wh atever").innerH TML);
    if(base){
    document.write( "<a href="+
    (1001 + Math.floor (Math.random() * (base-1001)) )+
    ".html>clic k</a>")
    }
    </script>

    Not tested.
    Mick



    Comment

    Working...