code

javascript kludges

A couple of inelegant solutions that I picked up trying to create my own hit counter

client side include

Insert this code whereever you need to include a repeated bit of text:
<script language="Javascript" src="URL to included
file"> </script>
The included file must be valid Javascript. Just take your HTML and wrap it inside document.write methods:

original HTML

<a href="index.html">home</a> |
<a href="archive.html">archive</a> |
<a href="sitemap.html">sitemap</a> |
<a href="about.html">about</a>

converted to Javascript

document.write ('<a href="index.html">home</a> |');
document.write ('<a href="archive.html">archive</a> |');
document.write ('<a href="sitemap.html">sitemap</a> |');
document.write ('<a href="about.html">about</a>');

Watch out for those quote marks! This trick can also be used to insert the output of CGI scripts, in case you have access to CGI but not to SSI. You just have to make the CGI script output Javascript as above.

call a CGI script from Javascript

This is often necessary if you need to pass variables from Javascript to a CGI script. The following passes the document.referrer value, as it is only available through Javascript.

var referrer=document.referrer;
document.write ('<script language="JavaScript"
src="spy.pl?page=' + page + '&referrer=' + referrer + '">' );        
document.write ('</script>');


Last update: 2001-04-24
code main | fato profugus