[thelist] Javascript Querystring?
Saila, Craig
Craig.Saila at bgminteractive.com
Mon Nov 18 11:14:01 CST 2002
> Is it possible to use some javascript to make all links on a
> page contain a querystring variable?
>
> eg get javascript to add '?foo=fee' to all links
I do that on my site to switch templates...
<http://www.saila.com/> (normal)
<http://www.saila.com/?lowfi> (text-only)
...but it only works in W3C-DOM-compatible browsers.
The code snippet here would check to see if the query string contained a
variable, say "?foo=fee", and if it did it would add "?foo=fee" to all
the links:
(where v = the query string, for example, "?foo=fee")
function changeLink(v){
var links = document.getElementsByTagName("a");
for(x = 0; x < links.length; x++){
v = escape(v)
var the_link = escape(links[x])
if((the_link.indexOf(v)!=-1){
links[x].setAttribute("href",unescape(the_link) + v)
}
}
You'd call this function at the end of a page or onload. You may also
want to add filters in here (for example some links may have a
hard-coded query string, others you may not want to change).
--
Cheers,
Craig Saila
------------------------------------------
craig at saila.com : http://www.saila.com/
------------------------------------------
More information about the thelist
mailing list