简体   繁体   English

专注于输入Google搜索

[英]focus on input Google search

I would like to develop a firefox extension that allows me to focus on the google search. 我想开发一个firefox扩展名,使我可以专注于google搜索。 https://www.google.fr https://www.google.fr

I tired to make document.getElementById("lst-ib").focus(); 我厌倦了使document.getElementById("lst-ib").focus(); , If I analyze the DOM with DOM inspector the input field have the id lst-ib , but the focus does not switch but if I made a document.getElementById("lst-ib").value = "test"; ,如果我使用DOM inspector分析DOM,则输入字段的ID为lst-ib ,但是焦点不会切换,但是如果我创建了document.getElementById("lst-ib").value = "test"; the word test appears good in the input field. 单词test在输入字段中看起来不错。 I feel that all the javascript functions work except the focus() . 我觉得除了focus()以外,所有的javascript函数都可以正常工作。

Is it therefore possible to focus on this field or google blocks this action maybe ? 因此,有可能专注于此领域还是Google阻止此操作?

EDIT 编辑

Js Google function event on focus : JS Google功能事件聚焦:

function(a, f) {
  if (d.length) {
     var g;
     if (!(g = a)) {
         g = {};
         var k = c.event;
         k && (k.keyCode && (g.keyCode = k.keyCode), g.i1 = !0)
     }
     g.dg = f || b;
     for (var k = g, l, m, n = 0, ba; ba = d[n++];) ba.sD ? m = !0 : l 
          || (ba.j1 ? QS_pWa(this, ba, k) : l = ba.Cg(k));
     if (m)
       for (n = 0; ba = d[n];) ba.sD ? d.splice(n, 1) : ++n;
     if (g.Uh) return delete g.Uh, g.i1 && (g = c.event || g), QS_Et(g), g.returnValue = !1
   }
}

But this is incomprehensible... 但这是无法理解的...

I think focus() is right and google isn't blocking that method, but because the focus is on Inspector, it does not seems focus on search input element. 我认为focus()是正确的,并且google并未阻止该方法,但是由于焦点位于Inspector上,因此它似乎并未专注于搜索输入元素。 Type this and click google page's margin: 输入此内容,然后单击Google页面的页边距:

setTimeout(() => document.getElementById("lst-ib").focus(), 2000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM