android - 电话间隙 : loading remote html

标签 android cordova

我正在寻找一种在 phonegap android 应用程序中加载远程 html 的方法。 我正在使用 super.loadUrl("file:///android_asset/www/hello.html"); 但如何加载远程 html 页面?

最佳答案

Venkat 非常简单,

只需使用http请求加载所需的html页面,

super.loadUrl("http://www.test.com/test1.html");

或者你可以像你一样加载本地html文件

super.loadUrl("file:///android_asset/www/hello.html");

并且在 hello.html 中使用 window.location 在 onLoad() javascript 函数中加载外部 html 页面。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <!-- Change this if you want to allow scaling -->
    <meta name="viewport" content="width=default-width; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>LoadUrl
    <script type="text/javascript" charset="utf-8">
    function onBodyLoad()
    {
        document.addEventListener("deviceready",onDeviceReady,false);
    }
    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    function onDeviceReady()
    {
    // do your thing!
      window.location="http://170.60.26.20:8099/Sencha/Html/index.html";
    }
    </script>
  </head>
  <body onload="onBodyLoad()">   
  </body>
</html>

请确保您在 android list 文件中设置了互联网权限。

关于android - 电话间隙 : loading remote html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10470380/

相关文章:

cordova - Android 和 iOS 上的本地存储有多永久?

javascript - 使用 Ñ 字符(拉丁语)在 PhoneGap 上的 SQLite 中查询不给出结果

javascript - Cordova 脚本未执行

Android Canvas - setWillNotDraw(false) 不起作用

java - 无法解析配置 ':app:_debugApkCopy' 的所有依赖项。找不到 com.google.android.gms :play-services-appindexing:10. 0.1

android - Android 上的 SMTP 代理守护进程

android - 为现有的 Spring MVC 应用程序(Spring Mobile 或 Phonegap)设计移动应用程序

android - NullPointerException 使用 AppCompat v21 在 Fragment 中获取 Google Map

c# - 如何从另一个项目启动 Activity

javascript - 适用于 Android、iOS 和 Windows 平板电脑的 Cordova 滑动事件检测选项