By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

create a variable link

P: n/a
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.txt" 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
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
asd987 wrote:
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.txt" 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

Use an SSI to include "counter.txt", format it something like the
following:

<p id="whatever" style="display:none">[number here]</p>
<script type="text/JavaScript">
var base=isNaN(document.getElementById("whatever").inn erHTML)?""
:+(document.getElementById("whatever").innerHTML);
if(base){
document.write("<a href="+
(1001 + Math.floor (Math.random() * (base-1001)) )+
".html>click</a>")
}
</script>

Not tested.
Mick

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.