Syntax Highlight Code On Any Page Using Google Code Prettify

| Posted by watashii | Filed under Programming, Web

prettify00

The Google Code Prettify is a JavaScript module that allows syntax highlighting of any code snippets on a HTML page.  Setting this up on any web page is a simple 3 step process, and is supported on most common browsers.

[Demo]   (Based on:  prettify-21-May-2009.zip)
[Download Source Files]

Read the rest of this entry »

Tags: , , , ,

Get URL Variables in JavaScript & HTML

| Posted by watashii | Filed under Java, Programming, Web

The following structure stores variables within a request URL:

http://www.mydomain.com/index.html?month=January&day=Tuesday

To read the variables within the index HTML file, we must process the URL string entirely, since there is no built-in functions which magically does it.  The following JavaScript demonstrates this:

function getUrlVars()
{
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}

To use the variables, we run the following to extract the values:

var myHash = getUrlVars();
alert(myHash['month']);   // prompts the value 'January'
alert(myHash['day']);     // prompts the value 'Tuesday'

Tags: , ,