Skip to content

Instantly share code, notes, and snippets.

@ardiwine
Last active September 8, 2017 18:42
Show Gist options
  • Save ardiwine/5c412b5ba56705d68ade to your computer and use it in GitHub Desktop.
Save ardiwine/5c412b5ba56705d68ade to your computer and use it in GitHub Desktop.
Appcelerator Titanium: Open external link from a webview on a native browser
var webview = Ti.UI.createWebview({
html: '[ PUT YOUR HTML HERE ]'
})
webview.addEventListener('beforeload', function(e) {
if (e.url.toString().indexOf('http') != -1 || e.url.toString().indexOf('www') != -1) {
// you can also check for mailto://
webview.stopLoading(true);
Ti.Platform.openURL(e.url);
};
});
@CILP
Copy link

CILP commented Jun 26, 2017

Hi @ardiwine a little modification that could help, Regards.

`var webview = Ti.UI.createWebview({
html: '[ PUT YOUR HTML HERE ]'
})

webview.addEventListener('beforeload', function(e) {
var url = e.url;

if (/^(www|http)/.test(url.toString())) {
    webview.stopLoading(true);
    Ti.Platform.openURL(url);
}

});`

@SteveOscar
Copy link

This is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment