Today I'd like to share my results on a good link behaviour in Apache Cordova's (5.x in my case) link behaviour using the InAppBrowser Plugin.
Context:
First of all the cordova plugins I'm using:
Problem:
I had to deal with several kinds of links in my InAppBrowser website. Some examples:
Google Adsense Advertisements (external links)
Social Media Links (external)
tel: links (tel: protocol)
whatsapp:// links (external application)
Internal links (Open inside the InAppBrowser)
Solution:
First I tried (not a good solution) ...
My first workaround was to react on the
"loadstop" event of the window object like this:
if (url.lastIndexOf(this.config.webAppUrl, 0) !== 0 && url.substr(0, 1) !== '/') {
window.open(url, '_system', null);
}
But that was just an ugly workaround and lead to several problems. It didn't work well.
... than I found out something better (good solution!):
Simply do some cordova-plugin-whitelist magic using config.xml to define the correct behaviour and everything works very well finally:
That's it!
Please leave a comment if this was helpful for you.