cordova启动首页,访问远程服务器web_app

来源:互联网 发布:农村淘宝网点查询 编辑:程序博客网 时间:2024/05/17 01:01

 

由于已经在微信浏览器(或者手机浏览器)中开发好了web应用,现在通过app打开应用访问服务页面

 

第一种尝试 —— 将web应用的代码一起打包到web应用中,页面全部从app本地加载代码,但是,web请求的数据是远程,因此跨域了

 

第二种尝试 —— 本地webview直接访问远程地址,就类似于浏览器访问远程一样,这样就不存在跨域,代码如下:

 

<!DOCTYPE html><html>    <head>                <meta name="format-detection" content="telephone=no">        <meta name="msapplication-tap-highlight" content="no">        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">        <title>Hello World</title>    </head>    <body>        <script type="text/javascript" src="cordova.js"></script>        <script type="text/javascript" src="js/index.js"></script>    </body>    <script>    window.location.href="http://www.sqhzg.cn/house/index.html#/index";    </script></html>

 

备注:

默认index.html页面中

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

 应该删除掉,否则页面无法正常跳转

 

 

修改config.xml配置文件,允许webview访问页面,否则app会拉动本地的浏览器显示内容

 

<?xml version='1.0' encoding='utf-8'?><widget id="com.jianan.wuye" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">    <preference name="loglevel" value="DEBUG" />    <feature name="Whitelist">        <param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />        <param name="onload" value="true" />    </feature>    <allow-intent href="market:*" />    <name>wuye</name>    <description>        A sample Apache Cordova application that responds to the deviceready event.    </description>    <author email="dev@cordova.apache.org" href="http://cordova.io">        Apache Cordova Team    </author>    <content src="index.html" />    <access origin="*" />    <allow-intent href="http://*/*" />    <allow-intent href="https://*/*" />    <allow-intent href="tel:*" />    <allow-intent href="sms:*" />    <allow-intent href="mailto:*" />    <allow-intent href="geo:*" />     <allow-navigation href="http://*/*" /> <allow-navigation href="https://*/*" /> <allow-navigation href="data:*" />  <access origin="*" /> <access origin="http://*/*" /> <access origin="https://*/*" />    </widget>

 

 

 

 

原创粉丝点击