Javascript “输入类型”;日期“;isn';不可编辑
当我创建上下文类型为“可编辑”的上下文菜单项时,当在Javascript “输入类型”;日期“;isn';不可编辑,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,当我创建上下文类型为“可编辑”的上下文菜单项时,当在标记上打开上下文菜单时,它会显示出来 chrome.contextMenus.create({ ... contexts: ["editable"] ... }); 当是一个普通文本框时,它可以工作,但是当它的类型为日期或时间时,菜单不再显示: <input type="date"> <!-- Nope --> 这是为什么?是否有办法使其显示(仅在可编辑元素上,包括不同类型的)?根据
标记上打开上下文菜单时,它会显示出来
chrome.contextMenus.create({
...
contexts: ["editable"]
...
});
当
是一个普通文本框时,它可以工作,但是当它的类型为日期
或时间
时,菜单不再显示:
<input type="date"> <!-- Nope -->
这是为什么?是否有办法使其显示(仅在可编辑元素上,包括不同类型的
)?根据说明,只有非只读、非禁用的文本输入元素是“可编辑的”
解决方案:动态更改上下文菜单项的context
使用鼠标/键盘事件处理程序为所有/指定的URL声明内容脚本,该事件处理程序检查聚焦元素,并将消息发送到上下文菜单项的上下文
到“页面”
或“可编辑”
- manifest.json:
"permissions": ["contextMenus"], "content_scripts": [{ "matches": ["<all_urls>"], "js": ["content.js"], "run_at": "document_start" }], "background": { "scripts": ["background.js"], "persistent": false },
- background.js:
chrome.contextMenus.create({ id: 'hello', title: 'Hello', contexts: ['editable'] }, function() { var ignoreErrors = chrome.runtime.lastError; }); chrome.contextMenus.onClicked.addListener(function(info, tab) { if (info.menuItemId == 'hello') { console.log('Hello'); } }); chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { chrome.contextMenus.update('hello', {contexts: [msg]}); });
“可编辑”
解决方案:动态更改上下文菜单项的context
使用鼠标/键盘事件处理程序为所有/指定的URL声明内容脚本,该事件处理程序检查聚焦元素,并将消息发送到上下文菜单项的上下文
到“页面”
或“可编辑”
- manifest.json:
"permissions": ["contextMenus"], "content_scripts": [{ "matches": ["<all_urls>"], "js": ["content.js"], "run_at": "document_start" }], "background": { "scripts": ["background.js"], "persistent": false },
- background.js:
chrome.contextMenus.create({ id: 'hello', title: 'Hello', contexts: ['editable'] }, function() { var ignoreErrors = chrome.runtime.lastError; }); chrome.contextMenus.onClicked.addListener(function(info, tab) { if (info.menuItemId == 'hello') { console.log('Hello'); } }); chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { chrome.contextMenus.update('hello', {contexts: [msg]}); });
“activeTab”
-只有权限集值得这么做。