chrome扩展学习 右键菜单实现代码
作者:
chrome扩展学习 右键菜单实现代码,需要的朋友可以参考下
manifest.json
{
"name": "我的右键",
"description": "chrome扩展学习---menu使用",
"version": "0.1",
"permissions": ["contextMenus", "tabs"],
"background": {
"scripts": ["menu.js"]
},
"manifest_version": 2
}
menu.js
function genericOnClick(info, tab) {
alert(info.linkUrl);
}
function selectionOnClick(info, tab) {
alert(info.selectionText);
}
var link = chrome.contextMenus.create({"title": "链接地址","contexts":["link"],"onclick":genericOnClick});
var selection = chrome.contextMenus.create({"title": "选中文字","contexts":["selection"],"onclick":selectionOnClick});
复制代码 代码如下:
{
"name": "我的右键",
"description": "chrome扩展学习---menu使用",
"version": "0.1",
"permissions": ["contextMenus", "tabs"],
"background": {
"scripts": ["menu.js"]
},
"manifest_version": 2
}
menu.js
复制代码 代码如下:
function genericOnClick(info, tab) {
alert(info.linkUrl);
}
function selectionOnClick(info, tab) {
alert(info.selectionText);
}
var link = chrome.contextMenus.create({"title": "链接地址","contexts":["link"],"onclick":genericOnClick});
var selection = chrome.contextMenus.create({"title": "选中文字","contexts":["selection"],"onclick":selectionOnClick});