javascript - 使用插件访问从 phonegap Cordova 中的外部 URL 加载 Webste

标签 javascript android ios cordova

我希望从我的 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/

相关文章:

ios - 如何从嵌套在 plist 文件的字典中的数组中访问随机值?

javascript - 模拟点击传单 map 项目

javascript - 如何在 Angular js中创建多列组合框

java 。 org.json 问题

java - 安卓媒体播放器

ios:创建一个 CoreData 对象而不立即持久化它

javascript - 使用 jQuery 将图像链接更改为 "#"

JavaScript 函数在 HTML 页面中不起作用

java - 来自旧手机 API 18 的可绘制资源的 Android Resources$NotFoundException

iphone - 使用 Google Analytics iOS SDK 跟踪应用内购买