I know that Google is the popular search engine for most folk, but I really think that Microsoft’s Bing system is better and offers up more useful results. To help Bing become more successful, I’d like to have a search box on my site that utilizes the Bing search engine. Is that possible?
I agree with you that Bing is becoming quite a credible competitor to Google and that the results are show in a useful form, including info that Google just doesn’t have. I’m not sure that it’ll every overtake the Google behemoth, but then again, just because Ferrari doesn’t sell more cars than Ford that doesn’t mean it’s not a cool car!
As with the other search systems I have unwrapped and reverse engineered on the site (including Google, Google Images and YouTube), the first step with figuring out how Bing works with search is to go onto the site itself and run a search, then look at the resultant URL.
A Bing search for “cherries” (get it?) produces its results against the URL:
Now we can unwrap this by knowing a bit about how method=get Web forms work:
action=http://www.bing.com/search q=pattern go= form=QBLH qs=n sk=
Based on my experience reverse-engineering other search forms, I am going to start with the most minimal possible search box:
<input type=”text” name=”q” />
<input type=”submit” value=”Go!” />
</form>
Here’s how it looks when we actually include it here on the blog entry:
Try it. Type in a search query and click on “Go!” to see what happens.
Functional, but a bit boring. Let’s make it a tiny bit more attractive by adding a bit of CSS:
<div style=”border:1px solid black;padding:5px;width:350″>
<center>
Search Bing: <input type=”text” name=”q” size=”30″ />
<input type=”submit” value=”Go!” />
</center>
</div>
</form>
Again, when I actually implement it here on the blog entry, this is what we get:
So that’s your answer. You can tweak and fiddle from here… 🙂
I see how to make the results open in a new window , but could the search box open a second window from the same search term like a bing result and a result from http://wow-armory.org/?s=1
Hi. I would like to display at most 5 bing search results in my site like Facebook does. How could I do that?
Hi Dave
How would you add a checkbox to this script so that you have the option of just searching your own site?
Hmm… This works for me in Firefox 3.6.6, Safari 5.0, and IE 8.0. (Maybe the CSS specs don’t specify that it should “work”, but it does, anyway?)
<div style=”text-align: center;”>
<img src=”photo.png”>
</div>
Ken, experimentation will reveal what I have always found a huge disappointment and flaw in the CSS positioning attribute: it only centers text containers, not graphical containers. In other words, using <div style=”text-align:center;”> will not actually center everything in that DIV tag, so I find that I still use the CENTER tags anyway. If there is another CSS attribute that centers everything in that DIV I would sure love to know about it!
Just curious why you use “<div style=…>” to set the style, but then use “<center>” separately. Couldn’t that just be part of the div’s style?