Created
February 28, 2014 23:26
-
-
Save purplecabbage/9282132 to your computer and use it in GitHub Desktop.
Cross platform access to the cordova config.xml file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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