Sunday, June 10, 2007

You need to use a Key for Google's AJAX search.  This key happens to be per domain sub folder.  Since you can get to my site via thisoldcode.net or thisoldcode.microfisch.com Googles search would throw an error depending which entry point you enter.  I don't seem to have the ability to forward all thisoldcode.microfisch.com traffic to thisoldcode.net ( I should but the godaddy settings are not taking).  In the search api documentation they load the search via a js file with a hard coded key.

<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=This Old Code Key" type="text/javascript"></script>

so I added a simple JavaScript function to dynamically write this include based on the website entry point.

    function SetGoogleSearchKey()
{
var DomainKey = 'This Old Code Key';
if( document.domain == "thisoldcode.microfisch.com" )
DomainKey = 'Microfisch Key';

var ScriptTag = 'script';//trick the bloody browser. document.write('<' + ScriptTag + ' src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=' + DomainKey + '" type="text/javascript"></' + ScriptTag + '>');
}
 

It would have been nice if Google's JS script file did not display an alert when it cannot load do to the key error. I would have simply allowed thisoldcode.microfisch.com to have the search. after all I don't really need two. But its cool.

posted by Aaron Fischer on Sunday, June 10, 2007 3:50:47 PM (Pacific Standard Time, UTC-08:00)   #    Comments [0]
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview