如何在chrome应用程序中动态更新版本号
How to dynamically update version number in chrome app?
我有一个谷歌chrome打包的应用程序,我想根据其清单文件更新该应用程序的about页面上的版本号。我的清单文件是这样的:
manifest.json
{
"manifest_version": 2,
"name": "Book Writer",
"version": "2.0.8.0",
"icons": {
"16": "images/Book-icon.png",
"48": "images/Book-icon.png",
"128": "images/Book-icon.png"
},
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": [
"storage",
"contextMenus"
]
}
重要部分是"版本":"2.0.8.0",
我的about页面的结构是这样的:
about.html
<!DOCTYPE html>
<head>
<title>about</title>
<link rel="stylesheet" type="text/css" href="/css/about.css">
</head>
<body>
<h1 class="main-header">book writer v 2.0.8.0</h1>
<h2 class="sub-header">This game was made by: Dragonloverlord</h2>
<h2 class="sub-header">LICENSE</h2>
<div class="license-div">
<code>
The MIT License (MIT)<br>
<br>
Copyright (c) 2014 dragonloverlord<br>
<br>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:<br>
<br>
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.<br>
<br>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.<br>
</code>
</div>
</body>
</html>
如果我不能直接从清单文件更新它,那么是否有一个符合angularjs-csp的方法来更新单个变量的编号,这样我所要做的就是将脚本链接到应用程序中任何需要更新版本号的页面?
您可以直接从清单更新:这就是chrome.runtime.getManifest API的用途。
在纯JavaScript中,您可以执行以下操作:
document.addEventListener('DOMContentLoaded', function () {
manifest = chrome.runtime.getManifest();
document.querySelector('h1.main-header').innerHTML = "book writer v " + manifest.version;
});
相关文章:
- d3基于用户选择动态更新节点
- 如何从相应的控制器动态更新标题和描述
- 根据CHECKBOX输入值动态更新DIV信息
- HTML动态更新滑块输入
- 如何使用ajax和jquery动态更新数组表
- 如何动态更新输入值属性
- 动态更新chartJ中的图表
- 动态更新Angular2指令中自定义属性的值
- jQuery动态更新数据键和值
- 如何在jQuery的.on()方法中动态更新按钮的ID选择器
- 使用 php/jquery 动态更新单个模态
- 在 Ionic 中动态更新滚动区域
- 具有动态更新的实时标题 (AJAX+jQuery)
- jQuery:动态更新 N 个最新值的列表
- 如何动态更新选择值
- 将URL路径与<a>attr('href')来动态更新.active类
- Jquery调整大小动态更新
- 在javascript中动态更新嵌套对象
- javascript中的文本框未正确动态更新
- 动态更新Ace Editor+Requirejs的语法高亮显示