javascript - Chrome 新标签自动对焦

标签 javascript jquery html google-chrome google-chrome-extension

我正在制作一个 Chrome 扩展,我正在使用以下内容:

list .json

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

cc.html

<style>body,html{padding:0;margin:0}</style>
<iframe src="theiframe.html" frameborder="0" height="200px" width="200px">
</iframe>

theiframe.html

<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>

当用户打开新标签时,自动对焦 将出现在地址栏中。我希望用户能够改变它。是否有任何代码可以自动自动聚焦搜索输入?

最佳答案

也许仅使用 iframe 是行不通的。但是您可以制作一个示例页面,当打开新选项卡时,该页面将重定向到您想要的页面,因此具有 autofocusinput 将自动聚焦。

这里有一个方法:


list .json

"chrome_url_overrides": {
    "newtab": "r.html"
},


r.html

<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>


s.js

window.location="https://www.google.com";


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

关于javascript - Chrome 新标签自动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14653857/

相关文章:

php - 视频在 IE 中不工作

javascript - 使用 Sammy.js 时如何移动到页面上的 anchor ?

javascript - 使用 'with' 关键字在 Javascript 中进行范围解析

javascript - 选择并提交来自/javascript 的图像

html - 使用 css 排序 div 元素

javascript - 为什么这个属性是在原型(prototype)上定义的,而不是在构造函数上?

javascript - 为什么我的 jqRouter.renderViewSuccess 事件处理程序被调用了两次?

javascript - 追加 div "n"次,其中 "n"是另一个 html div 内的值

html - 电子邮件中的 Outlook 中的双图像

php - 更改后刷新页面而不重置搜索查询