Prince
Prince

Reputation: 3

How to make a search box search google with HTML?

Lately, I've been working on a page in html which is supposed to search Google. I have a search box and a button but I'm wondering what the most efficient way to get the results from Google and display them on my page. If anyone knows I'd be glad if they helped me out.

{EDIT}

This is just a little project I'm working on. To be more specific I'd like to make it where what is typed in the search box gets taken from www.google.com/search and then the results of the Google search are displayed below.

Upvotes: 0

Views: 1472

Answers (2)

Logic1
Logic1

Reputation: 1847

So you're saying you want an HTML page with a single input and a submit button.

When the user enters text into the input and then presses submit what would you like to happen?

I see two basic approaches.

  1. Pass the search string as a parameter in the URL so the next page can be made aware of it using javascript. then use xmlhttprequest to grab the data from google and do a document.write to render the information to the user: example
  2. Insert a Div with some id in the page and then use the submit's onclick attribute to initiate an AJAX call that gets the data from google and then inserts it into the div's innerHTML without the need for multiple pages.

[UPDATE}

after looking into this it seems that XMLHttpRequest will not work with google and that the API is the way to go. source

Upvotes: 0

undefined
undefined

Reputation: 4135

Answer & Demo

You can create a custom google search engine for your sites, follow the steps, then get the code and paste it in a div inside the body tag. Here is a JSFiddle with an example of this (site:stackoverflow.com).

You can then edit the way the engine looks in the look and feel tab in the edit search menu.

How to edit the looks of a custom search engine

Hope this helps, good luck! :)

Upvotes: 1

Related Questions