在网页中添加Google搜索 [英] Add Google search in web page

查看:139
本文介绍了在网页中添加Google搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将搜索添加到静态站点.最简单的方法是通过在实际查询中附加"site:www.acme.com"来简单地查询Google,以便Google将搜索限制在该站点.

I'd like to add search to a static site. The simplest way is to simply query Google by appending "site:www.acme.com" to the actual query so that Google will limit search to that site.

理想情况下,我想在浏览器中执行此操作,以避免必须在服务器上安装PHP.使用表格,我不知道如何附加搜索项:

Ideally, I'd like to do this in the browser, to avoid having to install PHP on the server. Using a form, I don't know how to append the search items:

<form action=http://www.google.com?q="site:www.acme.com+...">
<input type=text id=search_item>
</form>

有人知道客户端解决方案吗?我应该为此使用一些JavaScript吗?

Does someone know of a client-side solution? Should I use some JavaScript for this?

谢谢.

当使用"method = get"和"input name = q value ="site:www.acme.com"时,浏览器实际上将使用"www.google.com?q="site调用Google: "www.acme.com某些项目",但我宁愿避免使用"site:www.acme.com"预设输入框,因为用户会发现这个奇怪的现象并可能将其删除.

When using "method=get" and "input name=q value="site:www.acme.com "", the browser will indeed call Google with "www.google.com?q="site:www.acme.com some item", but I'd rather avoid presetting the input box with "site:www.acme.com" because users will find this odd and might remove it.

推荐答案

您只需要将form方法设置为"get",在要搜索的网站上添加一个额外的隐藏元素,它将自动粘贴到这样的网址:

You just need to set the form method to "get", add one extra hidden element with the site you want to search and it will automatically paste it behind the URL as such:

<form action="https://google.com/search" method="get">
<input type="hidden" name="sitesearch" value="http://acme.com" />
<input type="text" name="q" />
</form>

因为这是默认情况下HTML表单的工作方式.

Because that is how HTML forms work by default.

这篇关于在网页中添加Google搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆