2014-02-06 20 views
1

我想创建一个可打开弹出窗口的Chrome扩展,并且我想在我的html文件中使用jQuery。在弹出式扩展插件中加载jquery

创建我的manifest.json

{ 
    "name": "My First", 
    "description": "Test App", 
    "version": "0.1", 
    "app": { 
    "background": { 
     "scripts": ["background.js"] 
    } 
    }, 
    "icons": { "16": "radio_tower-32.png", "128": "radio_tower-128.png" } 
} 

然后创建一个background.js

chrome.app.runtime.onLaunched.addListener(function() { 
    chrome.app.window.create('window.html', { 
    'bounds': { 
     'width': 250, 
     'height': 250 
    } 
    }); 
}); 

然后创建我的HTML页面

<!DOCTYPE html> 
<html> 
    <head> 
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script> 
    </head> 
    <body> 
    <a onclick="$('.playeraudio')[0].pause();">Stop</a> 
    <audio controls="controls" autoplay class="playeraudio"><source src="http://mystream.mp3" type="audio/mp3" /></audio> 
</body> 
</html> 

jquery的-1.11.0。 min.js在文件夹中,但点击不起作用。 我试图用改变background.js:

chrome.app.runtime.onLaunched.addListener(function() { 
    chrome.app.window.create('window.html', { 
    'bounds': { 
     'width': 250, 
     'height': 250 
    } 
    }); 
}); 
chrome.tabs.executeScript(null, { file: "jquery.js" }, function() { 
    chrome.tabs.executeScript(null, { file: "content.js" }); 
}); 

但它没有功能(content.js夹中)。有谁能够帮助我?我需要改变什么?由于

+0

你的html页面是否在插件之外工作?你的控制台是否有错误?在一个文件中,你引用''jquery.js“'在另一个文件中''jquery-1.11.0.min.js”'..? – Philipp

+0

是的抱歉,我在复制时发生错误。 – user3281544

+0

请不要修改您的代码以使现有答案失效。如果你必须的话,你应该问一个新的问题。 – Teepeemm

回答

1

我只是想在我工作的一个Chrome扩展的测试,并在控制台中得到这个错误:

Refused to execute inline event handler because it violates the following 
Content Security Policy directive: "script-src 'self' chrome-extension-resource:". 

对违规更多的细节:https://developer.chrome.com/extensions/contentSecurityPolicy.html#JSExecution

基本上你需要将onclick EventListener提取到它自己的JS文件中。

+0

现在jQuery的作品...但不是播放暂停...看到我贴的代码... – user3281544