2013-07-03 28 views
1

我創建了一個Chrome擴展,我想在源代碼當前頁面中添加一個javascript文件。我編寫這段代碼但不起作用。 事實上,我可以追加一個標籤就像在源代碼當前頁面的JavaScript,但不工作,我想借此錯誤不會在當前頁面的Chrome擴展中執行附加的JavaScript標記

Denying load of chrome-extension://lmainnigamjlkokflgjdkjdjbphifefb/remove2.js?_=1372832784584. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension. 
GET chrome-extension://invalid/ 
Failed to load resource 

這是我的代碼:

manifest.json的

{ 
    "manifest_version" : 2, 
    "name" : "Get URL", 
    "description" : "This is extension test-2", 
    "version" : "1.0", 

    "permissions" : ["tabs"], 

    "browser_action" : { 
     "default_title": "This is extension test-2", 
     "default_icon": "icon.png", 
     "default_popup" : "popup.html" 
    }, 
    "content_scripts": [ 
     { 
      "matches": [ "http://*/*", "https://*/*" ], 
      "js": ["jquery.js", "content.js"] 
     } 
    ], 

    "icons" : { 
     "19": "icon.png" 
    } 
} 

content.js

insertTooltip(); 

function insertTooltip() { 

    var ic = chrome.extension.getURL('remove2.js'); 
    console.log(ic); 
    var tooltip = '<script type="text/javascript" src="'+ic+'"></script>'; 
    console.log(tooltip); 
    $('body').append(tooltip); 
}; 

popup.html

<html> 
    <head> 
     <script src="get.js"></script> 
     <script src="content.js"></script> 
    </head> 
    <body> 
    <div id="show"></div> 

    </body> 
</html> 

get.js

var currentURL; 
chrome.tabs.getSelected(null, function(tab) { //<-- "tab" has all the information 
    currentURL = tab.url  //<-- return the url. 
    //console.log(currentURL) 
    if(currentURL) 
    { 
     //alert(currentURL); 
     var div = document.getElementById('show'); 
     div.innerHTML = currentURL; 
    } 
}); 

請指導我一下吧......

回答

1

您需要添加remove2 .js腳本到您的清單。

{ 
    ... 
    "web_accessible_resources": [ 
    "remove2.js" 
    ], 
    ... 
} 

更多信息here

+0

yessssssssssssssssssss ...................謝謝我的朋友:D – HarryP

相關問題