Change what the Google 404 Widget searches for - ASP.NET

by Jamie Snell 28. November 2008 11:01

We're using ASP.NETs custom error pages and I added the Google 404 Widget to our 404 custom error page. 
 
Googles 404 Widget is just some javascript that adds a google search box and some suggested pages that they may have been looking for. 
 
The file name for our custom error page was ~/FileNotFound.htm
 
The problem was since ASP.NET just redirects to the FileNotFound.aspx page it put 'File Not Found' in the search box.
 
This breaks the entire functionality of the 404 search widget. 
 
Using the following script it'll search using the wrong URL they typed in.  It's getting it from the AspxErrorPath query string item.
 
<style type="text/css">
#goog-wm
{
}
#goog-wm h3.closest-match
{
}
#goog-wm h3.closest-match a
{
}
#goog-wm h3.other-things
{
}
#goog-wm ul li
{
}
#goog-wm li.search-goog
{
display: block;
}
</style>

<script type="text/javascript">
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
 
var GOOG_FIXURL_LANG = 'en';
var GOOG_FIXURL_SITE = 'http://www.SiteDomain.com/';
var GOOG_FIXURL_URL = 'http://www. SiteDomain.com' + querySt('aspxerrorpath'); 
</script>

<script type="text/javascript" src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen