7

How will I be able to get the version number of my application in metro javascript?

For example, this is the 1.2 version of our application, how can I get the version number in my javascript metro code?

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
louis.luo
  • 2,921
  • 4
  • 28
  • 46

3 Answers3

11

Use this helper method to get the version as a complete string:

function getAppVersion() {
    var p = Windows.ApplicationModel.Package.current.id.version;
    return p.major + "." + p.minor + "." + p.build + "." + p.revision;
}

To display it to the user:

document.getElementById("version").innerHTML = "version " + getAppVersion();

This assumes you add this tag:

<span id="version"></span>
whitneyland
  • 10,632
  • 9
  • 60
  • 68
9

You can use the Windows.ApplicationModel.Package.current.id.version object to reference the version specified in your application manifest.

The version object contains "build, major, minor & revision" properties.

For further details, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.aspx

Bob Delavan
  • 647
  • 5
  • 6
0

How about this;


function getCurrentApplicationVersion() {
    var currentVersion = Windows.ApplicationModel.Package.current.id.version;
    var values = [];
    for (var key in currentVersion) {
        values.push(currentVersion[key]);
    }
    return values.join('.');
}
Lost_In_Library
  • 3,265
  • 6
  • 38
  • 70
  • 1
    You're making assumptions about the iteration order of Object Keys in JavaScript. See: http://stackoverflow.com/a/280861/227349 – JonnyReeves Feb 05 '13 at 16:17