我想创建一个可打开弹出窗口的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夹中)。有谁能够帮助我?我需要改变什么?由于
你的html页面是否在插件之外工作?你的控制台是否有错误?在一个文件中,你引用''jquery.js“'在另一个文件中''jquery-1.11.0.min.js”'..? – Philipp
是的抱歉,我在复制时发生错误。 – user3281544
请不要修改您的代码以使现有答案失效。如果你必须的话,你应该问一个新的问题。 – Teepeemm