Cordoba - Internal hyperlinks always open in Safari

I am very new to Cordoba, so maybe I do not quite understand its purpose. Let me start with what I'm trying to achieve as a whole.

We have an asp.net website that has mobile support, and I'm just trying to wrap an iPhone application. The site, of course, runs on the IIS server, so I just want the thin shell to launch the site and delete the address bar, navigation, etc. I understand that you can achieve this with the Cordova hybrid approach.

I followed the tutorial and launched the site to run in the xCode iPhone simulator, and it appeared exactly the way I wanted.

The problem I am facing is that hyperlinks within the site launch the landing page in the Safari browser. And from all my googling, it seems like this is the opposite problem of most people. It seems that most people struggle with open sites in the application, which basically block them from their application. I'm just trying to go from Page1 to page2 on my own website in the application.

I was able to reproduce this problem with a simple site, so I will post the corresponding bits. In this example, clicking on "Page 2" will open in Safari.

Website Asp.net:

page1.html

<html> <a href="page2.html">Page 2</a> </html> 

Page2.html

 <html> Page 2 </html> 

Cordoba:

Index.html

 <!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"> </head> <body> Cordova site </body> <script> window.location = "http://192.168.1.157:8081/Page1.html"; </script> </html> 

config.xml

 <?xml version='1.0' encoding='utf-8'?> <widget id="vsisolutions.testsite" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>Test Site</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" /> <plugin name="cordova-plugin-whitelist" spec="1" /> <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://192.168.1.157:8081/*" /> <allow-navigation href="*" /> <platform name="android"> <allow-intent href="market:*" /> </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> </platform> <engine name="ios" spec="~4.1.1" /> <plugin name="com.msopentech.authdialog" spec="~0.1.6" /> </widget> 

Thanks for the help!

+3
source share
4 answers

It was a mistake

This has been fixed on the latest released version of cordova-ios 4.2.0

This way, you don’t need to do any hacks to make it work anymore, you just need to use the allow-navigation tag to set the URLs that you want to allow for navigation inside the application, and the rest of them will open in safari. as you have allow-intent for all http and https urls.

+2
source

I found that in Cordoba, the WKWebView plugin (it can also appear in UIWebView) requests any other plugins to find out if they can use the URLs in the link. This was picked up by CDVIntentAndNavigationFilter and executed through logic, as in:

 - (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType: (UIWebViewNavigationType)navigationType { NSURL* url = [request URL]; switch (navigationType) { case UIWebViewNavigationTypeLinkClicked: // Note that the rejection strings will *only* print if // it a link click (and url is not whitelisted by <allow-*>) if ([self.allowIntentsWhitelist URLIsAllowed:url]) { // the url *is* in a <allow-intent> tag, push to the system [[UIApplication sharedApplication] openURL:url]; return NO; } // fall through, to check whether you can load this in the webview default: // check whether we can internally navigate to this url return ([self.allowNavigationsWhitelist URLIsAllowed:url]); } } 

Since type navigationType == UIWebViewNavigationTypeLinkClicked, it passed it to the browser via [[UIApplication sharedApplication] openURL: url];

Currently, I just found to hack this, and this should override this logic by handling the links in the same way, for example:

 switch (navigationType) { case UIWebViewNavigationTypeLinkClicked: // Note that the rejection strings will *only* print if // it a link click (and url is not whitelisted by <allow-*>) if ([self.allowIntentsWhitelist URLIsAllowed:url]) { // the url *is* in a <allow-intent> tag, push to the system // [[UIApplication sharedApplication] openURL:url]; return YES; } // fall through, to check whether you can load this in the webview default: // check whether we can internally navigate to this url return ([self.allowNavigationsWhitelist URLIsAllowed:url]); } } 

This is obviously not perfect, and I will ask the forum in Cordoba for the best solution that I will post here when I find it.

+2
source
 <a href="page2.html" target="_blank">Page 2</a> 

That should work.

0
source

Just changing allow-navigation to add with * worked:

 <allow-navigation href="http://yourwebsite/*" /> 
0
source

All Articles