2014-09-03 207 views
-1

我无法使用自定义扩展名在页面内容中调用我的jQuery隐藏主体。铬扩展background.js

background.js

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. 
    //alert(info.srcUrl); 

    //chrome.windows.create({ url: url, width: 520, height: 660 }); 
    }; 
}; 



window.addEventListener("load", initialize); 



function initialize(){ 
    if(jQuery){ 
     alert('yes'); 
    }else{ 
     alert('no'); 
    } 
    jQuery('body').hide(); 
} 

chrome.contextMenus.create({ 
    "title" : "Get image info", 
    "type" : "normal", 
    "contexts" : ["image"], 
    "onclick" : getClickHandler() 
}); 

manifest.js

{ 
    "name" : "Imageinfo", 
    "version" : "1.0.1", 
    "description" : "Get image info for images, including EXIF data", 
    "background" : { "scripts": ["jQuery.js", "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 
} 

我只是不想让身在本例。我确实得到了'是'的警报,但是之后没有。也许我错过了清单2的东西。我尝试了一些例子,但没有奏效。

谢谢。

回答

0

你确定你的清单是正确的吗?

尝试纠正你的清单,以配合这个

{ 
    "name" : "Imageinfo", 
    "version" : "1.0.1", 
    "description" : "Get image info for images, including EXIF data", 
    "manifest_version": 2, 

    "icons" : { 
    "16" : "imageinfo-16.png", 
    "48" : "imageinfo-48.png", 
    "128" : "imageinfo-128.png" 
}, 


    "background": { 
    "page": "background.html" 
    }, 

    "permissions": [ 
    "contextMenus", 
    "tabs", 
    "http://*/*", 
    "https://*/*" 
], 
"web_accessible_resources": [ 
    "jquery.js" 
    ], 
"content_scripts": [ 
    { 
     "js": ["jquery.js"] 
    } 
    ] 
} 

你需要创建一个将在其<head>标签下面的一个background.html页面

<script type="text/javascript" src="background.js"></script> 
<script type="text/javascript" src="jquery.js"></script>