Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome新标签自动对焦_Javascript_Jquery_Html_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript Chrome新标签自动对焦

Javascript Chrome新标签自动对焦,javascript,jquery,html,google-chrome,google-chrome-extension,Javascript,Jquery,Html,Google Chrome,Google Chrome Extension,我正在做一个chrome扩展,我正在使用下面的 manifest.json { "name": "Test extension", "version": "1.1", "description": "Test extension.", "icons": { "128": "icon_128.png" }, "chrome_url_overrides": {

我正在做一个chrome扩展,我正在使用下面的

manifest.json

{
        "name": "Test extension",
        "version": "1.1",
        "description": "Test extension.",
        "icons": {
            "128": "icon_128.png"
        },
        "chrome_url_overrides": {
            "newtab": "cc.html"
        },
        "manifest_version": 2
    }
"chrome_url_overrides": {
    "newtab": "r.html"
},
cc.html

    <style>body,html{padding:0;margin:0}</style>
    <iframe src="theiframe.html" frameborder="0" height="200px" width="200px">
    </iframe>
<style>body,html{padding:0;margin:0}</style>
<form action="http://www.example.com/search">
    <input autofocus="autofocus" tabindex="1" type="text" />
    <input tabindex="2" value="search" type="submit"/>
</form>
<html>
  <head>
    <title>Loading...</title> <!-- user friendly -->
    <noscript>
      <meta http-equiv="refresh" content="0; url=https://www.google.com"> <!-- in case javascript is disabled -->
    </noscript>
    <script src="s.js"></script>
  </head>
  <body></body>
</html>
body,html{padding:0;margin:0}
theiframe.html

    <style>body,html{padding:0;margin:0}</style>
    <iframe src="theiframe.html" frameborder="0" height="200px" width="200px">
    </iframe>
<style>body,html{padding:0;margin:0}</style>
<form action="http://www.example.com/search">
    <input autofocus="autofocus" tabindex="1" type="text" />
    <input tabindex="2" value="search" type="submit"/>
</form>
<html>
  <head>
    <title>Loading...</title> <!-- user friendly -->
    <noscript>
      <meta http-equiv="refresh" content="0; url=https://www.google.com"> <!-- in case javascript is disabled -->
    </noscript>
    <script src="s.js"></script>
  </head>
  <body></body>
</html>
body,html{padding:0;margin:0}
当用户打开新选项卡时,自动对焦将出现在地址栏中。我希望用户能够改变这一点。是否有自动对焦搜索输入的代码?

来自以下网站的提示:

不要依赖具有键盘焦点的页面。 当用户创建新选项卡时,地址栏总是首先获得焦点

正如Erik Kay(Chrome工程总监)在中指出的那样,Omnibox的预期行为是在默认情况下具有焦点,这是不可能改变的


同样地,这个bug被标记为
WontFix

可能仅仅使用
iframe
无法工作。但是,您可以创建一个示例页面,当打开一个新选项卡时,该页面将重定向到您想要的页面,因此具有自动对焦功能的
输入将自动对焦

以下是一种方法:


manifest.json

{
        "name": "Test extension",
        "version": "1.1",
        "description": "Test extension.",
        "icons": {
            "128": "icon_128.png"
        },
        "chrome_url_overrides": {
            "newtab": "cc.html"
        },
        "manifest_version": 2
    }
"chrome_url_overrides": {
    "newtab": "r.html"
},

r.html

    <style>body,html{padding:0;margin:0}</style>
    <iframe src="theiframe.html" frameborder="0" height="200px" width="200px">
    </iframe>
<style>body,html{padding:0;margin:0}</style>
<form action="http://www.example.com/search">
    <input autofocus="autofocus" tabindex="1" type="text" />
    <input tabindex="2" value="search" type="submit"/>
</form>
<html>
  <head>
    <title>Loading...</title> <!-- user friendly -->
    <noscript>
      <meta http-equiv="refresh" content="0; url=https://www.google.com"> <!-- in case javascript is disabled -->
    </noscript>
    <script src="s.js"></script>
  </head>
  <body></body>
</html>

这是最好的方法(可能也是唯一的方法)。

:)报告甚至引用了类似的文档。