本文介绍了Cordova/Phonegap在主Cordova Webview中加载外部站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的

What i want

我有一个外部Web资源,我希望Cordova Webview可以简单地打开并能够在其内部导航中进行导航.

I have external web-resource that i want cordova webview to simple open and be able to navigate through its inner navigation.

说明

Description

InAppBrowser文档说

InAppBrowser docs said

所以我有一个受信任的外部链接(例如,我想 http://www.google.com 加载到主Web视图中,并希望通过window.location.href或用户链接单击来控制其过程.

So i have an trusted external links (let's say http://www.google.com i want to load in main webview and want to control its process though window.location.href or user links click.

我尝试过的

What i tried

使用最新的cordova并已插入的生成的hello world应用

Generated hello world app with latest cordova and inserted

window.location.href = 'http://www.google.com/'

转到其onDeviceReady.它的配置已经有了(我试图将其更改为具体地址)

to its onDeviceReady. It's config was already having (and i tried to change it to concrete adress)

<access origin="*" />

我还尝试了window.open和手动用户链接单击,但是我所拥有的只是在外部浏览器中打开链接的对话框,而不是在同一Webview中呈现它.我还尝试了InAppBrowser扩展程序,该扩展程序在禁用导航栏时可以正常使用,但是它存在通信问题,并且不适用于手动链接舔和window.location.href更改.

I also tried window.open and manual user link clicks, but all i've got is dialog to open link in external browser instead of rendering it inside same webview.I also tried InAppBrowser extension, that works fine when i disable navigation bar but it has communication problems and doesn't work on manual link licks and window.location.href changes.

推荐答案

在iOS和android上使用以下规则解决了此问题:

Solved this issue using following rules on both ios and android:

<access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="tel:*" />
<allow-navigation href="sms:*" />
<allow-navigation href="mailto:*" />
<allow-navigation href="geo:*" />

如果您遇到相同的问题,还需要了解以下内容:

If you stuck on same problem you also need to know following:

这篇关于Cordova/Phonegap在主Cordova Webview中加载外部站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:34
查看更多