Javascript Chrome新标签自动对焦
我正在做一个chrome扩展,我正在使用下面的 manifest.jsonJavascript 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": {
{
"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>
这是最好的方法(可能也是唯一的方法)。:)报告甚至引用了类似的文档。