[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]cordova 首页为远程网页时,后续链接在外部浏览器中打开的问题。

上一篇:[备忘]cordova,android工程,config.xml备忘
下一篇:[备忘]cordova的deviceready事件,是每个页面成功后都会触发的。

添加日期:2015/10/31 23:55:06 快速返回   返回列表 阅读11753次
前提:cordova为5.3.3版本

在config.xml中指定
<content src="http://www.xxx.com/mobile/" />
这样的远程地址,首页打开无问题,

但是后续的链接,点击后,会在外部的浏览器中打开。
当然,如果你用jquery mobile所有网页都通过ajax方式读取,是没问题的。
但是,有些链接是用data-ajax=false的,即直接打开网页。
开始以为是jquery mobile的问题,但把它的js去掉,依然如此。

开始认为是cordova框架内部的问题。

研究半天,下断点,在CordovaWebViewImpl.class中发现:


@Override
        public boolean onNavigationAttempt(String url) {
            // Give plugins the chance to handle the url
            if (pluginManager.onOverrideUrlLoading(url)) {
                return true;
            } else if (pluginManager.shouldAllowNavigation(url)) {
                return false;
            } else if (pluginManager.shouldOpenExternalUrl(url)) {
                showWebPage(url, true, false, null);
                return true;
            }
            LOG.w(TAG, "Blocked (possibly sub-frame) navigation to non-allowed URL: " + url);
            return true;
        }


return true就是在外部浏览器中打开。
其中,shouldAllowNavigation是循环插件,有一个插件返回true或false就返回了。
第一个就是白名单插件,呵呵

看文档,只要在config.xml中添加:
<allow-navigation href="http://*/*" />
即可允许所有http请求。

添加后,shouldAllowNavigation方法返回true,onNavigationAttempt返回false,
从而在app 内部打开。

哈哈~~~

困惑了好几天。

 

评论 COMMENTS
guest795085529
2016/2/25 16:06:53
我 添加了但是在ios平台下依然报ERROR Internal navigation rejected - <allow-navigation> not set for url='https://www.baidu.com/' 请问有解决办法没有?
guest_qq_87538812
2016/6/7 13:16:42
谢谢。我也解决问题了。最开始写成大写了navigation这个。后来改为小写,就可以在app内部打开页面了。

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved