Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Created February 28, 2014 23:26
Show Gist options
  • Save purplecabbage/9282132 to your computer and use it in GitHub Desktop.
Save purplecabbage/9282132 to your computer and use it in GitHub Desktop.
Cross platform access to the cordova config.xml file.
(function(){
var configPath = "../config.xml";
if( ["android","amazon-fireos"].indexOf(cordova.platformId) > -1 ) {
configPath = "../../android_res/xml/config.xml";
}
else if( ["blackberry10","firefoxos"].indexOf(cordova.platformId) > -1 ) {
configPath = "config.xml";
}
Object.defineProperty(cordova,'configPath', {enumerable: true, value: configPath });
})();
// And sample use :
function readConfig() {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
var parser = new DOMParser();
var doc = parser.parseFromString(xhr.responseText, "application/xml");
alert("Description : " + doc.getElementsByTagName("description").item(0).textContent);
});
xhr.open("get", cordova.configPath, true);
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment