I didn't even think of that, you're completely right. If you have links targeting a frame or another window you don't want to lose that functionality. You can use a generalized function that sets a querystring value in a URL to do it and use it anywhere. Something like this:
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="Javascript">
<!--
// return the current timestamp as a string
function currentTimestamp()
{
var now = new Date();
var ts = new Array(
now.getFullYear().toString(),
now.getMonth().toString(),
now.getDay().toString(),
now.getHours().toString(),
now.getMinutes().toString(),
now.getSeconds().toString())
var i;
var retval = '';
//pad one-digit values to two and concatenate
//the order is yyyymmddhhnnss
for (i=0; i<ts.length; i++)
{
if (ts[i].length < 2) ts[i] = '0' + ts[i];
retval += ts[i];
}
return (retval);
}
//update a querystring value in a URL or append
//it to the set if it does not already exist.
function setQuerystringElement(url, element, value)
{
var newUrl = url;
var params = url.split('?');
var param;
var i;
var found = false;
//params will have either one or two entries, where
//entry 0 if the base URL and entry 1 is the querystring
if (params.length == 1)
{
//url has no querystring, so just append element
return newUrl += '?' + element + '=' + escape(value);
}
else
{
//save the base url from up above
newUrl = params[0];
//divide the querystring into name/value pairs
params = params[1].split('&');
for (i=0; i<params.length; i++)
{
//divide each pair into a name and value
param = params[i].split('=');
if (param[0].toLowerCase() == element.toLowerCase())
{
//update the value of the element
param[1] = value;
found = true;
}
//append the parameter to the URL
newUrl += (i == 0) ? '?' : '&';
newUrl += param[0] + '=' + escape(param[1]);
}
//if the element was not already in the URL, add it
if (!found) newUrl += '&' + element + '=' + escape(value);
}
return (newUrl);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<A HREF="temp.html" target="_blank" onclick="javascript:this.href=setQuerystringElement(this.href, 'time', currentTimestamp()); return true;">Link</A>
</BODY>
</HTML>