从JavaScript插件访问config.xml首选项 [英] Access config.xml preferences from JavaScript plugins
问题描述
在我的项目 config.xml
中添加了自定义偏好设置:
In my project's config.xml
I added a custom preference:
<preference name="FooBar" value="Baz" />
plugin.js 我想访问此类功能的值。
Then, in my custom plugin's JavaScript inside <plugin>/www/plugin.js
I want to access the value of such feature.
Cordova是否将这些值暴露给JavaScript端?我在相关文档中找不到任何信息。
Does Cordova exposes those values to the JavaScript side? I couldn't find any information in the documentation about it.
尝试:
var argscheck = require('cordova/argscheck');
argscheck.getValue('FooBar'); // Returns just FooBar
推荐答案
iOS,WP7,WP8,Windows8和可能的Ubuntu
You could use following code on iOS, WP7, WP8, Windows8, and probably Ubuntu
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", "../config.xml", true);
xhr.send();
}
您必须从../ config.xml
到../../ android_res / xml / config.xml
取自Cordova邮寄,其中讨论了答案:
https://www.mail-archive.com/dev@cordova.apache.org/msg14313.html
Taken from Cordova mailing where discussed answer: https://www.mail-archive.com/dev@cordova.apache.org/msg14313.html
此外没有官方的阅读配置插件:
https: //github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
Also there not-official plugin for reading configuration: https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
这篇关于从JavaScript插件访问config.xml首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!