使用HTML表单创建Google搜索框 [英] Creating a Google search box using HTML form
问题描述
因此,我正在尝试在我的网站上插入一个搜索表单,该表单会将用户及其查询重定向到Google搜索.
So I am trying to insert a search form on my website that will redirect the user with their query to Google Search.
我以前可以使用以下方法做到这一点:
I used to be able to do this using:
<form role="search" method="get" id="searchform" class="searchform" action="http://www.google.co.uk/search?hl=en-GB&source=hp&q=">
<div id="gform">
<label class="screen-reader-text" for="s"></label>
<input type="text" value="" name="s" id="s">
<input type="submit" class="btn fa-input" value="" style="font-family: FontAwesome;">
</div>
</form>
但是,这不再起作用.我猜这是因为Google更改了搜索URL,但是我无法使用Google当前的URL复制这种效果.
However, this no longer works. I'm guessing this is because Google have changed the search URL, but I am unable to replicate this effect by using Google's current URL.
有什么办法解决这个问题吗?
Any idea how to fix this?
推荐答案
看来我自己也解决了这个问题
Hi all it seems I have solved the problem myself
<div id="gform">
<label class="screen-reader-text" for="s"></label>
<input type="text" value="" name="q" id="s">
<input type="submit" class="btn fa-input" value="" style="font-family: FontAwesome;">
</div>
解决我的问题的关键是name="q"
.这就是使Google搜索正常工作所需要的;基本上这是因为Google希望q
作为名称
The key here that resolved my issue is name="q"
. This is what you need to make google search work; basically this is because google expects q
as the name
这篇关于使用HTML表单创建Google搜索框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!