我希望从我的 Cordova Phonegap 项目中的外部 URL 加载我的应用程序 (Android/iOS) 的内容。虽然我可以在应用程序中加载网站,但没有插件访问权限。我曾尝试在本地应用程序和网站上托管插件,但这些方法似乎都不起作用。
那么如何在 cordova 中使用插件访问从外部 url 加载网站?
编辑 1:我现在正在尝试提供 Android Cordova 中 Assets 文件夹的 URL。但是出现如下错误。
Error: [Error] initializing Cordova: Class Not Found.
最佳答案
您可以使用 AJAX 请求加载页面。 尝试关注此 article :
/**
* Load page into url
*
* @param url The url to load
*/
function loadPage(url) {
var xmlhttp = new XMLHttpRequest();
// Callback function when XMLHttpRequest is ready
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState === 4){
if (xmlhttp.status === 200) {
document.getElementById('container').innerHTML = xmlhttp.responseText;
}
}
};
xmlhttp.open("GET", url , true);
xmlhttp.send();
}
在主文件中
/**
* Function called when page has finished loading.
*/
function init() {
// Load first page into container
loadPage("screen1.html");
}
关于javascript - 使用插件访问从 phonegap Cordova 中的外部 URL 加载 Webste,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33563235/