【发布时间】:2017-05-14 16:10:04
【问题描述】:
上下文:
- 使用 JavaScript 编写谷歌浏览器扩展
- 使用上下文菜单库
- 用户应该能够右键单击文本框,选择 chrome 扩展,选择“插入文本”,然后该文本将插入到选定的文本框中。
- 我使用的是纯 javascript,请不要使用 jquery 或 AJAX。
- 我无法编辑 HTML 页面,因为它可能是任何带有 HTML 文本框或可编辑字段的通用网页。
到目前为止我的代码:
//the menu item
var menuItem_insert = chrome.contextMenus.create({"title": "Insert Timestamp", "contexts":[context], "onclick:": insertTimestamp});
//the onclick
function insertTimestamp(info, tab) {
//if info.editable is true then
alert(info.editable); //for debugging
//CODE GOES HERE: need to insert timestamp here
}
问题: 如何将文本插入我可能没有“ID”的选定文本框中?
【问题讨论】:
-
PS,ajax 是纯javascript。并且与你想在这里做什么无关。
-
你想做什么something like this?
标签: javascript google-chrome-extension contextmenu