nativescript-webview-interface icon indicating copy to clipboard operation
nativescript-webview-interface copied to clipboard

open link from webview

Open peppeg85 opened this issue 7 years ago • 2 comments
trafficstars

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

peppeg85 avatar Jul 05 '18 12:07 peppeg85

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);
        }
      });

mtenus avatar Oct 14 '19 08:10 mtenus

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

peppeg85 avatar Oct 14 '19 10:10 peppeg85