tech.zpoley.net

quick little hacks 
Filed under

Javascript

 

Javascript: Server callback on window unload

I'm using this simple cross-browser script to send tracking information back to the server when users leave a page.

Here's an example page.

I've tested it across Safari4.0.5/MobileSafari4.0.0+/Chrome5.0.375/Firefox3.6.3 and IE 6/7/8.

Filed under  //   Cross-browser   Javascript   callback   onunload   tracking  

Comments [0]

Accessing script src CGI params in Javascript

This has come up a few times now as a way to avoid server side coding and use Javascript more dynamically based on the CGI parameters passed in the src attribute of the <script> tag.  This script has been cross-browser tested in Chrome5+/Safari4+/FF3.6+/IE6+.

The way this script works is:

  • create/increment global index of this script in the DOM
  • find all script tags currently in the DOM
  • count occurences of this script using the sentinel __JSCGI=1
  • assign scriptElement variable to the current instance of the script
  • parse CGI parameters from src attribute

Being setup this way also allows the script to be included in the DOM multiple times specifying different CGI parameters to determine different functionality for the script. 

A simple demo can be found here using the cgi.js file here.

If you have a better way of doing this please do share.

Filed under  //   CGI   Javascript  

Comments [0]