如何在Google Chrome扩展程序中引用版本信息? [英] How to reference the version information in a Google Chrome extension?

查看:126
本文介绍了如何在Google Chrome扩展程序中引用版本信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

  chrome.tabs.create({url:URL here})

code>

在我的LRG中打开一个新选项卡。对于这个URL,我想附加在 manifest.json 文件中指定的扩展版本号:

 version:1.2,

在创建新选项卡时,我在javascript中访问版本号?解析方案

您可以获取自己的清单和版本通过使用以下内容:

  var url = chrome.extension.getURL(manifest.json); 
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e){
if(xhr.readyState == 2&&xhr.status == 200){
var manifest = JSON.parse(xhr。 responseText的);
alert(Version:+ manifest.version);
}
};

xhr.open(GET,url);
xhr.send();

获得版本号后,您可以执行您需要的选项卡。


I use

chrome.tabs.create({url:"URL here"})

to open a new tab in my LRG. To this URL I want to append the version number of the extension, which is specified in the manifest.json file:

"version": "1.2",

How can I access the version number in javascript at the time of creating the new tab?

解决方案

You can fetch your own manifest and the version by using the following:

var url = chrome.extension.getURL("manifest.json");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
  if(xhr.readyState == 2 && xhr.status == 200) {
     var manifest = JSON.parse(xhr.responseText);
     alert("Version: " + manifest.version);
  }
};

xhr.open("GET", url);
xhr.send();

Once you have the version number you can do your tab stuff that you need to do.

这篇关于如何在Google Chrome扩展程序中引用版本信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆