tbr
02-15-2007, 01:28 AM
Hi! Simplified code highlighting the important parts for my problem:
[...]
<script type="text/javascript">
var random_sequence = '<a href="just/a/regular/path.htm?' + generate_digit() + generate_digit() + generate_digit() + '">This is a link.</a>';
document.write(random_sequence);
function generate_digit(){
- Here goes a function that returns a random number or letter -
}
</script>
[...]
Explanation: I'm creating a link to 'just/a/regular/path.htm?[three random digits go here]'. On that page, another Javascript takes the random digits to affect some of its content.
The reason I'm creating the random sequence on this page instead of on the next one, is because I want the new page to have a URL that will give exactly the same result every time, so I can't use any random functions on that page. This is important, a copy + paste of the URL must generate the same content every time, even on a different computer at a different time.
The way I do it here works fine mostly, but there is one little problem that may confuse the user. If someone clicks this auto generated link and opens it in a new tab or window, the same link will be left in the background. If they click this link again later it would lead them to an identical page, which they may not have expected. This could cause some problems if the don't notice it.
How do I prevent that? I need some way of generating the random sequence on the click instead of on load. A regular onclick and then a redirect is bad cause it breaks all control over the link. The only way that I can see right now is to send them to a dummy page that only generates the URL and then quickly redirects the user there, but that's also pretty ugly, and you wouldn't be able to right click > copy link either.
I would prefer it if I could write the <a> tag normally in HTML and just generate the actual URL on the fly, that would solve my problem, but href="javascript:generate_URL()" doesn't seem to accept returns. :(
Any ideas?
[...]
<script type="text/javascript">
var random_sequence = '<a href="just/a/regular/path.htm?' + generate_digit() + generate_digit() + generate_digit() + '">This is a link.</a>';
document.write(random_sequence);
function generate_digit(){
- Here goes a function that returns a random number or letter -
}
</script>
[...]
Explanation: I'm creating a link to 'just/a/regular/path.htm?[three random digits go here]'. On that page, another Javascript takes the random digits to affect some of its content.
The reason I'm creating the random sequence on this page instead of on the next one, is because I want the new page to have a URL that will give exactly the same result every time, so I can't use any random functions on that page. This is important, a copy + paste of the URL must generate the same content every time, even on a different computer at a different time.
The way I do it here works fine mostly, but there is one little problem that may confuse the user. If someone clicks this auto generated link and opens it in a new tab or window, the same link will be left in the background. If they click this link again later it would lead them to an identical page, which they may not have expected. This could cause some problems if the don't notice it.
How do I prevent that? I need some way of generating the random sequence on the click instead of on load. A regular onclick and then a redirect is bad cause it breaks all control over the link. The only way that I can see right now is to send them to a dummy page that only generates the URL and then quickly redirects the user there, but that's also pretty ugly, and you wouldn't be able to right click > copy link either.
I would prefer it if I could write the <a> tag normally in HTML and just generate the actual URL on the fly, that would solve my problem, but href="javascript:generate_URL()" doesn't seem to accept returns. :(
Any ideas?