简体   繁体   English

如何在Chrome应用中动态更新版本号?

[英]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.

相关问题 如何从数据库动态更新号码 - How to Dynamically Update A Number From A Database 如何在Chrome应用更新时提醒用户? - How to alert user upon update of chrome app? 如何在Rails应用程序中动态更新变量 - How to update variable dynamically within Rails app 如何使用chrome应用程序窗口动态调整textarea的大小? - how could I make a textarea dynamically resize with the chrome app window? 如何使用AJAX成功函数更新动态创建的号码? - How do I update a dynamically created number with an AJAX success function? 如何让TeamCity更新指定文件中的构建版本号? - How to have TeamCity update the build version number in a specified file? 如何从Razor页面使用版本号参数更新JavaScript文件 - How to update JavaScript files with version number parameter from Razor page Chrome应用程序:如何更新在Chrome应用程序主窗口中创建的辅助窗口元素的内容? - Chrome App : How to update the content of an element of a secondary window created in the main window of a Chrome App? 在Chrome中检测插件的版本号 - Detect plugin's version number in Chrome 如何从 angular 应用程序动态添加/删除/更新元标记 - How to add/remove/update meta tags from angular app dynamically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM