【问题标题】:Why HTML5 form doesn't show me google search results?为什么 HTML5 表单不显示谷歌搜索结果?
【发布时间】:2021-07-24 02:54:18
【问题描述】:
<form action="https://www.google.com/search?q=" method="get">
    <input type="text" name="search" id="search">
</form>

每当我在input 中输入内容并按回车键时,它就会转到https://www.google.com/webhp?search=my+search。为什么它不通过 google 显示结果?

【问题讨论】:

标签: html google-search


【解决方案1】:

基于this:

Google.com/webhp (Google co webhp) 是一种重定向病毒,它会影响浏览器的设置并将我们重定向到其他网站。如果您想在 Google 搜索中搜索某些内容,它会将我们带到一些有害页面,而不是正常页面。

对于谷歌搜索,试试这个:

var form = document.querySelector("form");

form.addEventListener("submit", function (e) {
  e.preventDefault();
  var search = form.querySelector("input[type=search]");
  search.value = search.value;
  form.submit();
});
<form action="https://google.com/search"  type="GET">
  <label>
     Search Google: 
     <input type="search" name="q">
   </label>

  <input type="submit" value="Go">

</form>

【讨论】:

  • @Plaban 请注意,sn-p 在我的计算机上运行良好。但是 Stack sn-p 似乎有问题
猜你喜欢
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
  • 2019-06-04
相关资源
最近更新 更多