Loading remote html in PhoneGap or Cleaver (Cordova) on iOS

一笑奈何 提交于 2019-12-02 18:53:39
Moonwalker

Here is the answer. What a joy...

excellent article on dynamic page loading in PhoneGap and Cordova

Precisely what I needed. The second part of the project was to enable native code to force the loading of external web services - I accomplished this by called stringByEvaluatingJavaScriptFromString on the Cleaver web view .

[webview stringByEvaluatingJavaScriptFromString:@"app.loadExternal('www.usatoday.com')]; is the code that works like a charm:)

Viola - I have a Cleaver view capable of loading external html content with complete two-way communication between the javascript app and the native container.

Inside your index.html file do something like this (for the point 2)

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript">
     function onBodyLoad(){     
        document.addEventListener("deviceready", onDeviceReady, false);
     }
     function onDeviceReady(){
         window.location.href = <your_remote_url>
     }
}
</script>

For the point 3, your remote content should import cordova.js and the interaction (native / web) will work as if it was local content.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!