The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Adding Search to my Blog

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
David Cumps

Posts: 319
Nickname: cumpsd
Registered: Feb, 2004

David Cumps is a Belgian Student learning .NET
Adding Search to my Blog Posted: Jan 12, 2005 8:35 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by David Cumps.
Original Post: Adding Search to my Blog
Feed Title: David Cumps
Feed URL: http://weblogs.asp.net/cumpsd/rss?containerid=12
Feed Description: A Student .Net Blog :p
Latest .NET Buzz Posts
Latest .NET Buzz Posts by David Cumps
Latest Posts From David Cumps

Advertisement
After reading Heather's post about searching and taking a look at Geoff Appleby's JavaScript function I decided to add a Search box to my blog as well.

Here's a step by step explanation on how to add it:

  • Go to your blog's Admin section.
  • Go to Options.
  • Go to Configure.
  • Add the following to 'Static News/Announcement':
    1<h3>Search</h3> 
    2<input class="BlogSearch" type="text" name="searchBox" id="blogSearchText" value="" onkeypress="return blogSearch(event, this);">
    3<input type="button" value="Search" onclick="return blogSearch2('blogSearchText');" class="BlogSearchButton">
    4<script type="text/javascript">
    5
    6function blogSearch(event, oInput) {
    7 var keyCode = (event) ? event.keyCode : keyStroke.which;
    8 if (keyCode == 13) {
    9    top.location = 'http://www.google.be/search?q=' + escape(oInput.value) + '+inurl%3Acumpsd+site%3Aweblogs.asp.net';
    10    return false;
    11 } return true;
    12}
    13
    14function blogSearch2(oInputId) {
    15 var oInput = document.getElementById(oInputId);
    16 top.location = 'http://www.google.be/search?q=' + escape(oInput.value) + '+inurl%3Acumpsd+site%3Aweblogs.asp.net';
    17 return false;
    18}
    19</script>
  • Replace cumpsd with your blog url.
  • Save.
  • Admire your new search.
If you want to use MSN as a search engine use the following code (and replace cumpsd with your own url):
1<h3>Search</h3> 
2<input class="BlogSearch" type="text" name="searchBox" id="blogSearchTextMSN" value="" onkeypress="return blogSearchMSN(event, this);">
3<input type="button" value="Search" onclick="return blogSearchMSN2('blogSearchTextMSN');" class="BlogSearchButton">
4<script type="text/javascript">
5
6function blogSearchMSN(event, oInput) {
7 var keyCode = (event) ? event.keyCode : keyStroke.which;
8 if (keyCode == 13) {
9    top.location = 'http://search.msn.com/advresults.aspx?q=' + escape(oInput.value) + '%20cumpsd&FORM=SMCA&adv_f=all&adv_dom=weblogs.asp.net&adv_depth=&adv_dt=html&adv_dt=pdf&adv_dt=ppt&adv_dt=msword&adv_dt=x';
10    return false;
11 } return true;
12}
13
14function blogSearchMSN2(oInputId) {
15 var oInput = document.getElementById(oInputId);
16 top.location = 'http://search.msn.com/advresults.aspx?q=' + escape(oInput.value) + '%20cumpsd&FORM=SMCA&adv_f=all&adv_dom=weblogs.asp.net&adv_depth=&adv_dt=html&adv_dt=pdf&adv_dt=ppt&adv_dt=msword&adv_dt=x';
17 return false;
18}
19</script>
Update: Fixed script to work with Firefox as well (removed window.navigate and fixed event parameter and keyCode)
Update2: Added escape(), MSN version and site: restriction
Update3: Fixed MSN version, had a typo in the function name and id

Read: Adding Search to my Blog

Topic: Custom events in VB.Net Previous Topic   Next Topic Topic: [Cool Tool] How could I miss Copernic Desktop Search?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use