Cordova Wrapper应用程序内部链接加载在应用程序,外部链接加载在浏览器中 [英] Cordova Wrapper App Where Internal Links Load In App, External Links Load In Browser
问题描述
我有一个简单的 Cordova 包装应用程式指向外部网页,但未定义任何自己的资料检视。
I have a simple Cordova wrapper app which points to an external webpage, without defining any of its own views.
我想从该域中的所有内部链接加载到应用程序中,但所有外部链接( http://twitter.com 等)加载到系统浏览器中,因此这些网页具有后退/转发功能。
I would like all internal links from that domain to be loaded inside the app, but all external links (http://twitter.com, etc) to be loaded in the system browser, so the pages have Back / Forward functionality.
在具有视图的普通应用程序中,我可以设置 target ='_ system'
在默认浏览器中加载链接,或使用cordova-plugin-inappbrowser 在网络浏览器视图中显式打开链接。不幸的是,在这种情况下,我没有编辑服务器端代码的能力,所以需要一个在应用程序内工作的解决方案。
In a normal app with views, I could set target='_system'
to load links in the default browser, or use the cordova-plugin-inappbrowser to explicitly open links in a web browser view. Unfortunately in this case I don't have the ability to edit the server side code, so need a solution that works within the app.
如果我定义 config.xml
,因此内部和外部链接都会在应用程序中加载。
If I define the config.xml
as such, then both internal and external links are loaded in app.
<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
如果我定义 config.xml
allow-intent
,则内部和外部链接在系统浏览器中打开。
If I define the config.xml
with allow-intent
, then internal and external links are opened in the system browser.
<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
其他有建议使用自定义javascript来覆盖目标
到 _system
,但是由于我没有自己的意见,我不能。
Others have suggested using custom javascript to override the target
to _system
, however since I don't have my own views I can't really do that.
可以为 allow-intent /github.com/apache/cordova-plugin-whitelist\">cordova-plugin-whitelist ,以包含所有不是内部网域的网址?
Is it possible to define allow-intent
for the cordova-plugin-whitelist in such a way to include all URLs that are not the internal domain?
或者我需要以某种方式重写 MainViewController
中的 shouldStartLoadWithRequest
code> [[UIApplication sharedApplication] openURL:url] ?
Or will I need to somehow override shouldStartLoadWithRequest
in MainViewController
and then call [[UIApplication sharedApplication] openURL:url]
?
推荐答案
确定,在进行一些实验和建议后, Hayyaan ,我能够提出 allow-navigation
和 allow-intent
这是我的目的。
Ok, after some experimenting and suggestions from Hayyaan, I was able to come up with combination of allow-navigation
and allow-intent
which served my purpose.
<content src="https://example.com/" />
<access origin="*" />
<allow-navigation href="about:*" />
<allow-navigation href="https://example.com/*" />
<allow-navigation href="https://*.example.com/*" />
<allow-navigation href="https://*.facebook.com/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
现在,来自网站域的所有内部链接都已加载到应用程序中
Now all internal links from the website domain are loaded in the app, while external links are loaded in the system browser.
注意,我包括< allow-navigation href = https://*.facebook.com/*/>
允许加载Facebook库,否则我收到了错误。
Note, I included <allow-navigation href="https://*.facebook.com/*" />
to allow loading of Facebook libraries otherwise I received an error.
ERROR Internal navigation rejected -
<allow-navigation> not set for url='https://staticxx.facebook.com/connect/xd_arbiter.php?
还包括< allow-navigation href =about:* />
And also included <allow-navigation href="about:*" />
to avoid an error for about:blank
.
ERROR Internal navigation rejected - <allow-navigation> not set for url='about:blank'
希望这可以帮助有同样问题的其他人 >:)
Hopefully this helps someone else with the same problem :)
这篇关于Cordova Wrapper应用程序内部链接加载在应用程序,外部链接加载在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!