[英]How to use external javascript in chrome extension
我正在编写chrome扩展程序,并且想使用jQuery和simpleweather.js 。
扩展的目的是在新选项卡中显示具有良好背景图像的外部温度。
当我在外部使用脚本时,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="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 simpleWeather,然后再调用js。
我解决了问题。 您只需要更改脚本的顺序。 HTML:
<head>
[...]
<script src="jquery-3.1.1.min.js"></script>
<script src="jquery.simpleWeather.min.js"></script>
<script src="javascript.js"></script>
</head>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.