【问题标题】:Phonegap and ios - onDeviceReady function does not fire in external webpagePhonegap 和 ios - onDeviceReady 功能不会在外部网页中触发
【发布时间】:2013-09-17 10:56:59
【问题描述】:

我目前正在IOS中使用JQuery制作phonegap。

Phonegap的初始页面是index.html,其他页面是远程服务器的外部网页,通过iframe标签查看。

我想从 WebView 中显示的外部网页在 Phonegap 中打开 InAppBrowser。

为此,我在网页中编写了如下源代码,

    <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; 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, target-densitydpi=device-dpi" />
      <script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
      <script type="text/javascript">
     function onBodyLoad(){     
        document.addEventListener("deviceready", onDeviceReady, false);
     }
     function onDeviceReady(){
         alert(" remote page ready!");
     }
}
</script> 

         <title>Hello World</title>
        <script>

            function move_temp()
            {
                window.open("http://www.google.com","_blank","location=no");
            }

            </script>
    </head>
    <body onload="onBodyLoad()">


                                <p> THIS IS REMOTE PAGE!</p>
                <a href="javascript:move_temp();">erwjkl</a>
            </div>
        </div>
    </body>
</html>

我在 phonegap 中的白名单设置是“*”,所以白名单政策应该没有问题。

似乎 onDeviceReady 函数没有触发。因此,网页不会绑定到使用 InAppBrowser 模块所需的原生级别。

有什么解决办法?

提前致谢:)

【问题讨论】:

    标签: javascript ios cordova


    【解决方案1】:

    您应该只附加 deviceready 侦听器而不是使用 onload,并且您的代码还有一些其他问题,例如您如何调用函数来打开远程窗口。您的代码应如下所示:

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; 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, target-densitydpi=device-dpi" />
            <title>Hello World</title>
            <script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
            <script type="text/javascript">  
                document.addEventListener("deviceready", onDeviceReady, false);
    
                function onDeviceReady(){
                    alert(" remote page ready!");
                }
    
                function move_temp() {
                    window.open("http://www.google.com","_blank","location=no");
                }
            </script>
        </head>
        <body>
            <p> THIS IS REMOTE PAGE!</p>
            <a href="#" onclick="move_temp()">erwjkl</a>
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多