一个简单的上下文菜单例子:
manifest.json
{ "name" : "Imageinfo", "version" : "1.0.1", "description" : "Get image info for images, including EXIF data", "background" : { "scripts": ["background.js"] }, "permissions" : [ "contextMenus", "tabs", "http://*/*", "https://*/*" ], "minimum_chrome_version" : "6.0.0.0", "icons" : { "16" : "imageinfo-16.png", "48" : "imageinfo-48.png", "128" : "imageinfo-128.png" }, "manifest_version": 2 }
background.js
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** * Returns a handler which will open a new window when activated. */ function getClickHandler() { return function(info, tab) { // The srcUrl property is only available for image elements. var url = 'info.html#' + info.srcUrl; // Create a new window to the info page. chrome.windows.create({ url: url, width: 520, height: 660 }); }; }; /** * Create a context menu which will only show up for images. */ chrome.contextMenus.create({ "title" : "Get image info", "type" : "normal", "contexts" : ["image"], "onclick" : getClickHandler() });