Firefox 插件和扩展:获取用户输入

发布于 2024-10-03 10:46:47 字数 355 浏览 4 评论 0 原文

设置:假设您单击此页面上的某处,并且您有一个 Firefox 扩展,它通过插入带有

进行响应在文档中键入“text”>,位于您单击的位置。

问题:我似乎无法让此文本字段接受用户输入。它几乎似乎是只读的。我必须在 chrome.manifest 或其他地方设置某种配置吗? Firefox 扩展允许以这种方式获取用户输入吗?如果是这样,有人可以指出我正确的方向吗?

注意:我已经能够使用 prompt(); 设置该值,但我宁愿像平常一样输入

The setup: Say you click somewhere on this page, and you've got a Firefox extension that responds by inserting a <div> with an <input type="text"> into the document, positioned at the spot where you clicked.

The problem: I can't seem to get this text field to accept user input. It almost seems to be read-only. Is there some sort of configuration I have to set in chrome.manifest or elsewhere? Is getting user input this way allowed in Firefox extensions? If so, could someone please point me in the right direction?

Note: I've been able to set the value by using prompt(); but I'd rather just type in the <input> like normal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2024-10-10 10:46:47

您是否使用 event.preventDefault() 来捕获鼠标点击?这可能就是文本框看起来只读的原因——它永远无法获得焦点。要解决此问题,请使用:

textbox.addEventListener('click', function(event) {
    event.stopPropagation();
}, false);

这将阻止单击事件冒泡到用于拦截大多数鼠标单击的通用事件处理程序。

Are you using event.preventDefault() to trap mouse clicks? That could be the reason why the text box seems read only – it can never gain focus. To fix this, use:

textbox.addEventListener('click', function(event) {
    event.stopPropagation();
}, false);

This would keep the click event from bubbling up to your general event handler used to intercept most mouse clicks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文