shripalsoni04 / nativescript-webview-interface

Plugin for bi-directional communication between webView and android/ios
MIT License
88 stars 35 forks source link

open link from webview #35

Open peppeg85 opened 6 years ago

peppeg85 commented 6 years ago

hi, i feed the webview from an html source, how can i capture the tap on a link event to open the link with an external browser? i've seen the various functions like

function handleEventFromWebView(){ oWebViewInterface.on('anyEvent', function(eventData){ // perform action on event }); }

function emitEventToWebView(){ oWebViewInterface.emit('anyEvent', eventData); }

function callJSFunction(){ oWebViewInterface.callJSFunction('functionName', args, function(result){

});

}

i think i could use one of them, but how capture the 'tap on link' event (ios and android)? thank you

mtenus commented 4 years ago

Hi

@peppeg85 You could use an event 'loadStarted', then handle link and use "openUrl" method from utils library

  webView.on('loadStarted', (args: LoadEventData) => {
    if(args.url.indexOf('some_string')==-1) {
            utils.openUrl(args.url);
        }
      });
peppeg85 commented 4 years ago

hello, thank you, but I solved with the https://github.com/Notalib/nativescript-webview-ext plugin, thank you again,