Skip Navigation | Home | Code Samples | Articles | Links | About | Contact Me | Make a Payment

CGI Object

Access the variables in the cgi object in two ways

To initialize the cgi object, just include the following 7 lines of code within a <script> block in the head of your document.

var cgi = new Object();
    cgi.http_host = location.host;
    cgi.http_user_agent = navigator.userAgent;
    cgi.http_cookie = document.cookie;
    cgi.https = (location.protocol == 'https:\/\/') ? 'on' : 'off';
    cgi.path_info = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
    cgi.query_string = (location.search) ? ((location.search.indexOf(') != -1) ? location.search.substring(1, location.search.indexOf(')) : location.search.substring(1)) : '';
    cgi.script_name = cgi.path_info;
    cgi.http_referer = document.referrer;

Alternatively, you can download an external JavaScript file and include it in your HTML document like this:.

<script language="JavaScript" type="text/javascript">
<!-- 
  var cgi = new Object();
// -->
</script>
<script language="JavaScript" type="text/javascript" src="{path to file}cgi.js"></script>