[英]How to dynamically update version number in chrome app?
I have a google chrome packaged app and I would like to update the version number on the app's about page based off of its manifest file. 我有一个google chrome打包的应用程序,我想根据清单文件更新该应用程序“关于”页面上的版本号。 My manifest file is like so:
我的清单文件是这样的:
manifest.json 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"
]
}
Important part being "version": "2.0.8.0", 重要部分是“版本”:“ 2.0.8.0”,
and my about page is structured like so: 我的关于页面的结构如下:
about.html 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>
If I can not update it directly from the manifest file then is there a angularjs csp compliant method to update the number off of a single variable so all that I have to do is link a script to any page in the app that needs the version number updated? 如果我不能直接从清单文件更新它,那么有一个与angularjs csp兼容的方法来更新单个变量的编号,所以我要做的就是将脚本链接到应用程序中需要版本号的任何页面更新?
You can update directly from the manifest: This is what the chrome.runtime.getManifest API is for. 您可以直接从清单中进行更新:这是chrome.runtime.getManifest API的用途。
In pure JavaScript, you would do something like this: 在纯JavaScript中,您将执行以下操作:
document.addEventListener('DOMContentLoaded', function () {
manifest = chrome.runtime.getManifest();
document.querySelector('h1.main-header').innerHTML = "book writer v " + manifest.version;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.