konstantinbueschel
5/30/2016 - 9:05 AM

Appcelerator Titanium: Open link clicks from remote web view in system or other view

Appcelerator Titanium: Open link clicks from remote web view in system or other view

$.webView.addEventListener('beforeload', function(e) {
  
  if ((OS_IOS && e.navigationType == Titanium.UI.iOS.WEBVIEW_NAVIGATIONTYPE_LINK_CLICKED) 
    || (OS_ANDROID && e.url !== $.webView.getUrl())) {        
  
    // stop the event     
    e.bubble = false;
    e.cancelBubble = true;
    
    // stop the url from loading        
    $.webView.stopLoading();
    
    //opens up the clicked URL for bill in new webView         
    var link = e.url;         
    var args = {url: link};
    
    // open link in my default webView for iOS         
    var newWebView = Alloy.createController('defaultWebView', args).getView();         
    
    newWebView.open();
    
    // or let the system open it
    Ti.Platform.openURL(e.url);
  }
});