0
我正在写一个Chrome扩展,我想使用jQuery和simpleweather.js。
扩展的目的是在新选项卡中显示具有良好背景图像的室外温度。
当我在外部使用脚本时,HTML网站正在工作并显示温度,但扩展名无效。
HTML:如何在Chrome扩展中使用外部JavaScript
<head>
<title>Nová karta</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.1.0/jquery.simpleWeather.min.js"></script>
<script src="javascript.js"></script>
</head>
清单:
{
"browser_action": {
"default_title": "TimePage",
"default_popup": "popup.html"
},
"description": "",
"chrome_url_overrides": {
"newtab": "timepage.html"
},
"permissions": [
"tabs",
"cookies"
],
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": [ "https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js", "https://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.1.0/jquery.simpleWeather.min.js" ],
}
],
"manifest_version": 2,
"name": "Temperature",
"version": "1.0"
}
当我包括脚本本地HTML到同一文件夹中timepage.html
所在,网站无法正常运作和甚至不显示温度和扩展不工作。
HTML:
<head>
<title>Nová karta</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.css">
<script src="weather/jquery.simpleWeather.min.js"></script>
<script src="jquery.js"></script>
<script src="javascript.js"></script>
</head>
清单:
{
"browser_action": {
"default_title": "TimePage",
"default_popup": "popup.html"
},
"description": "",
"chrome_url_overrides": {
"newtab": "timepage.html"
},
"permissions": [
"tabs",
"cookies"
],
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": [ "jquery.simpleWeather.min.js", "jquery-3.1.1.min.js" ],
}
],
"manifest_version": 2,
"name": "Temperature",
"version": "1.0"
}
可能的复制[简单的jQuery在浏览器扩展程序弹出
我解决了这个问题。你只需要改变脚本的顺序。 HTML:
的来源
2016-11-13 00:57:38 Beny