cordova-plugin-wkwebview-engine icon indicating copy to clipboard operation
cordova-plugin-wkwebview-engine copied to clipboard

Tel or mailto links not working on WKWebview

Open jay34fr opened this issue 4 years ago • 12 comments

Bug Report

Problem

http(s) links are working, not tel: or mailto: with WKwebview. It's working with UIwebview

What does actually happen?

Nothing. Message in Xcode : "Failed to load webpage with error: unsupported URL"

I found several discussion but I don't know how to implement them on Cordova. https://stackoverflow.com/questions/33643326/catch-and-call-telephone-number-in-wkwebview https://stackoverflow.com/questions/44835703/why-is-wkwebview-not-opening-a-telephone-link-in-ios-9 https://stackoverflow.com/questions/51460119/how-can-i-tap-a-phone-number-with-wkwebview

Thx in advance. Jay

jay34fr avatar Apr 15 '20 13:04 jay34fr

I could not get Tel or Mail to work in the simulator and I wasn't seeing any errors in Xcode. Both are working on a physical device though (iPhone 6. iOS 12.4.5).

BradCB avatar Apr 15 '20 15:04 BradCB

Thanks BradCB. Not working from my side on the device too, iPhone 11, iOS 13

jay34fr avatar Apr 15 '20 15:04 jay34fr

Could you show your the code that is not working?

JamalAPI avatar Apr 20 '20 21:04 JamalAPI

Any news about this?

Vito96 avatar Jun 12 '20 11:06 Vito96

I didn't find any solution yet...

jay34fr avatar Jun 15 '20 15:06 jay34fr

@Vito96 : I put these functions in my app.js and it's working now

`// URL link with InAppBrowser Plugin $(document).on('click', 'a[href^=http], a[href^=https]', function(e){

        e.preventDefault();
        var $this = $(this); 
        var target = $this.data('inAppBrowser') || '_blank';

        if(device.platform == "Android" && $this.attr('href').split('.').pop() == 'pdf') { // Fix PDF Android
            window.open('https://docs.google.com/viewer?url='+$this.attr('href'), target);
        } else {
            window.open($this.attr('href'), target, 'location=no,closebuttoncaption=< Fermer,toolbarposition=top,presentationstyle=fullscreen,transitionstyle=crossdissolve, usewkwebview=yes,toolbarcolor=#666db0,closebuttoncolor=#ffffff');
        }

    });

            //  MAILTO & TEL in InAppBrowser Plugin
    $(document).on('click', 'a[href^=mailto], a[href^=tel]', function(eb){

        eb.preventDefault();
        var $this = $(this); 
        var target = $this.data('inAppBrowser') || '_system';

        if(device.platform == "Android" && $this.attr('href').split('.').pop() == 'pdf') { // Fix PDF Android
            window.open('https://docs.google.com/viewer?url='+$this.attr('href'), target);
        } else {
            window.open($this.attr('href'), target );
        }

    });`

jay34fr avatar Jun 19 '20 09:06 jay34fr

You can just use the last version of InAppBrowser (4.1.0 for now), and open the external link* using "cordova.InAppBrowser.open" instead of "window.open". Also, include the "hidden=yes", like this (it fixed some problems in iOS):

cordova.InAppBrowser.open('https://www.google.com/', '_system', 'hidden=yes,location=yes');

*It also works with "mailto", "tel", "whatsapp"... for Android, you just have to allow the intent and give permissions in config.xml file, like this:

<access launch-external="yes" origin="tel:*" />
<access launch-external="yes" origin="mailto:*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />

Finally, if you want all page loads in your app to go through the InAppBrowser, you can simply hook "window.open" during initialization:

$ionicPlatform.ready(function () {
 if (ionic.Platform.isWebView()) {
   window.open = cordova.InAppBrowser.open;
 }
}

fernandoghisi avatar Dec 09 '20 18:12 fernandoghisi

Adding this was sufficient for me to get tel: links working:

document.addEventListener("deviceready", function () {
    if (device.platform == 'iOS') {
        $(document).on('click', 'a[href^=mailto], a[href^=tel]', function (e) {
            e.preventDefault();
            var href = $(this).attr('href').replaceAll(' ', ''); // It doesn't like spaces in the phone number
            cordova.InAppBrowser.open(href, '_system');
        });
    }
}, false);

jwasnoggin avatar Dec 11 '20 03:12 jwasnoggin

Install the latest inappbrowser plugin, and using the following code: window.cordova.InAppBrowser.open('tel:xxxxxxx','_system');

Netpolice avatar Dec 15 '20 18:12 Netpolice

window.cordova.InAppBrowser.open('tel:xxxxxxx','_system');

Hi @Netpolice i already implemented it but it's still not working , probably you have another solution that calling tel: in InAppBrowser

hanifmhd avatar Feb 01 '21 08:02 hanifmhd

Any update?

victorvhpg avatar May 21 '21 11:05 victorvhpg

Adding this was sufficient for me to get tel: links working:

document.addEventListener("deviceready", function () {
    if (device.platform == 'iOS') {
        $(document).on('click', 'a[href^=mailto], a[href^=tel]', function (e) {
            e.preventDefault();
            var href = $(this).attr('href').replaceAll(' ', ''); // It doesn't like spaces in the phone number
            cordova.InAppBrowser.open(href, '_system');
        });
    }
}, false);

encodeURIComponent($(this).attr('href'))

myarth avatar Dec 08 '21 03:12 myarth

We are archiving this repository following Apache Cordova's Deprecation Policy. We will not continue to work on this repository. Therefore all issues and pull requests are being closed. Thanks for your contribution.

jcesarmobile avatar Jan 08 '23 23:01 jcesarmobile