且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Google搜索框添加到我的网站?

更新时间:2023-01-26 14:23:31

不好意思回复一个较旧的问题,但我想澄清最后一个问题。 / p>

对表单使用get方法。
当您的输入字段名称为g时,它会生成如下所示的URL:

  https ://www.google.com/search? g = [来自输入字段的值] 

但是当您使用Google进行搜索时,您会注意到以下网址:

  https://www.google.nl/search?q=谷歌+搜索+栏

Google使用qQuerystring变量作为搜索查询。
因此,将您的字段从g重命名为q可以解决问题。


I am trying to add a Google search box to my own website. I would like it to search Google itself, not my site. There was some code I had that use to work, but no longer does:

<form method="get" action="https://www.google.com/search">
<input type="text" name="g" size="31" value="">
</form>

When I try making a search, it just directs to the Google homepage. Well, actually it directs here: https://www.google.com/webhp

Does anyone have a different solution? What am I doing wrong?

Sorry for replying on an older question, but I would like to clarify the last question.

You use a "get" method for your form. When the name of your input-field is "g", it will make a URL like this:

https://www.google.com/search?g=[value from input-field]

But when you search with google, you notice the following URL:

https://www.google.nl/search?q=google+search+bar

Google uses the "q" Querystring variable as it's search-query. Therefor, renaming your field from "g" to "q" solved the problem.