Chrome扩展程序:主页上的焦点输入字段

问题描述 投票:0回答:1

我有一个带输入框和按钮的HTML页面。我想要一个可以专注于输入元素的chrome扩展。

HTML页面 -

<html>
    <body>
        <input type="text" name="box" />
        <button type="button" onclick="clicked()">Click</button>
        <script>
            //document.getElementsByName("box")[0].focus(); <--- this works. But I don't want this.
        </script>
    </body>
</html>

我注入的脚本 -

chrome.runtime.onMessage.addListener(function(message, sender, response){
    if(message.action==="start"){
            document.getElementsByName("box")[0].focus(); //<---want this to work. Currently unable to :(
            console.log("started");
    }
});

我得到了启动日志,但我的元素没有集中。

休息文件(即popup.html和popup.js)未显示,因为它们工作正常且与此无关。

我尝试在输入元素上模拟鼠标点击事件(来自here),但该方法也失败了。

对此有任何帮助表示赞赏。打开基于jquery的解决方案。

谢谢。

javascript html google-chrome google-chrome-extension
1个回答
0
投票

HTML文档准备好后发送消息。

© www.soinside.com 2019 - 2024. All rights reserved.