Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我刚开始使用新的 chrome 扩展,但是我找不到如何在 JavaScript 中获取确切的插入符号(文本光标)位置
代码
chrome.commands.onCommand.addListener(function (command) { console.log('Command:', command); if (command == "OpenRightclick-menu") { // Get coordinates } });
您可以从内容脚本访问当前光标位置。
如果你有一个元素的 DOM 节点,你可以检查selectionStart和selectionEnd属性。
如果您没有 DOM 节点 - 您可以查看此问题的答案。