View Full Version : Need help with adding google custom search in my website

10-29-2010, 08:47 AM
my website uses a javascript file to load a common header for all the pages. I would like to add a custom search box to my header. There's a code given by google for adding custom search but this code works in HTML pages. My header file is a .js file. Need help in modifying this code so that the same can be used in js file.

Code provided by google:

<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('0135638010087:ab1xoe7erpy');
}, true);

I tried modifying like this, but its not working:

document.write("<div id='cse' style='width: 100%;'>Loading</div>");
document.write("<script src='http://www.google.com/jsapi' type='text/javascript'></script>");
document.write("<script type='text/javascript'>");
document.write("google.load('search', '1', {language : 'en'});");
document.write("google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('001356680356738010084:ab1f807erpy');");
document.write("}, true);");


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum