Creating a Google search box using HTML form

假如想象 提交于 2019-12-21 17:50:50

问题


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="&#xf002;" style="font-family: FontAwesome;">
  </div>
</form>

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?


回答1:


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="&#xf002;" style="font-family: FontAwesome;">	
</div>
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


回答2:


This snippet creates a simple google search box

<form action="http://www.google.com/search" method="get">
    <input type="text" name="q"/>
    <input type="submit" value="search" />
</form>


来源:https://stackoverflow.com/questions/30305582/creating-a-google-search-box-using-html-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!