0

我的请求对我来说似乎很简单,但我无法让它工作。

我想将 Cordova 用作我现有博客的移动容器。我正在使用windows平台进行测试。

这将是我的 config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.testcordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>MyAPP</name>    
    <access origin="*" />    
    <content src="http://vmorneau.me/" />
</widget>

但是在构建应用程序时它给了我一个 APPX1404 错误。

然后我在内容 src 中放回“index.html”并进行简单的重定向(2 种不同的方式),但没有任何反应。只是一个空白页,好像没有任何东西被重定向。

这是我的 index.html 文件:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>My Redirect</title>
    </head>
    <body>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript"> 
            document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady() {
                window.location.href="http://vmorneau.me";             
                //window.open("http://vmorneau.me", '_blank');
            } </script>
    </body>
</html>
4

2 回答 2

0

在您的 index.html 中,添加一个脚本来处理“deviceready”事件(这意味着您的 cordova 库已准备好),然后在其中尝试重定向。

于 2014-11-08T10:57:22.713 回答
0

我试过了,遇到了同样的问题。当我查看控制台输出时,显示了超时错误。不知道为什么。我想你发现了一个错误。

11-08 06:02:27.169: D/CordovaWebView(1420): >>> loadUrl(http://www.johnwargo.com)
11-08 06:02:27.169: D/PluginManager(1420): init()
11-08 06:02:27.189: D/CordovaWebView(1420): >>> loadUrlNow()
11-08 06:02:27.469: D/CordovaActivity(1420): Resuming the App
11-08 06:02:27.579: D/SoftKeyboardDetect(1420): Ignore this event
11-08 06:02:27.879: I/Choreographer(1420): Skipped 82 frames!  The application may be doing too much work on its main thread.
11-08 06:02:28.019: D/gralloc_goldfish(1420): Emulator without GPU emulation detected.
11-08 06:02:28.269: D/SoftKeyboardDetect(1420): Ignore this event
11-08 06:02:28.349: I/ActivityManager(378): Displayed com.johnwargo.test/.CordovaApp: +3s376ms
11-08 06:02:28.379: D/AndroidRuntime(1405): Shutting down VM
11-08 06:02:28.399: D/dalvikvm(1405): Debugger has detached; object registry had 1 entries
11-08 06:02:28.689: I/Choreographer(378): Skipped 40 frames!  The application may be doing too much work on its main thread.
11-08 06:02:29.519: D/CordovaWebViewClient(1420): onPageStarted(http://www.johnwargo.com/)
11-08 06:02:29.519: D/CordovaActivity(1420): onMessage(onPageStarted,http://www.johnwargo.com/)
11-08 06:02:43.129: D/ConnectivityService(378): Sampling interval elapsed, updating statistics ..
11-08 06:02:43.289: D/ConnectivityService(378): Done.
11-08 06:02:43.289: D/ConnectivityService(378): Setting timer for 720seconds
11-08 06:02:47.229: E/CordovaWebView(1420): CordovaWebView: TIMEOUT ERROR!
11-08 06:02:48.229: W/ProcessCpuTracker(378): Skipping unknown process pid 1484
11-08 06:03:00.489: D/dalvikvm(1420): GC_FOR_ALLOC freed 317K, 10% free 3711K/4108K, paused 265ms, total 266ms

这是一个有效的示例应用程序:

<!DOCTYPE html>
<html>

<head>
  <title>Redirect</title>
  <meta charset="utf-8" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
  <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
  <script type="text/javascript" charset="utf-8">
    function onBodyLoad() {
      console.log("body load");
      alert("Body Load");
      document.addEventListener("deviceready", onDeviceReady, false);
    }

    function onDeviceReady() {
      console.log("Entering onDeviceReady");
      window.open('http://www.johnwargo.com', '_blank');
    }
  </script>
</head>

<body onload="onBodyLoad()">
  <h1>Redirect</h1>
  <p>This is a sample Cordova application.</p>
</body>

</html>
于 2014-11-08T11:11:14.080 回答