Skip to content

Instantly share code, notes, and snippets.

@mogya
Created September 29, 2012 17:53
Show Gist options
  • Save mogya/3804712 to your computer and use it in GitHub Desktop.
Save mogya/3804712 to your computer and use it in GitHub Desktop.
[titanium] webview which open any url on the web browser
var win = Titanium.UI.createWindow({
navBarHidden : true,
exitOnClose:true
});
var webView = Ti.UI.createWebView({
width:'100%'
});
webView.addEventListener('beforeload',function(e){
if (e.url.match(/^file:\/\//) ){
Ti.API.debug('beforeload.local file.');
}else{
Ti.API.debug('remote url. open with browser!');
Ti.Platform.openURL(e.url);
webView.stopLoading();
}
});
webView.addEventListener('load',function(e){
if (e.url.match(/^file:\/\//) ){
Ti.API.debug('load. local file.');
}else{
if (webView.canGoBack()){
Ti.API.debug('force first URL.');
webView.goBack( );
}
}
});
// var url = 'test.html';
// if (Titanium.Platform.name == 'android'){
// url = Ti.Filesystem.resourcesDirectory+'/'+url;
// }
// webView.url = url;
webView.setHtml('<html><body>Hello, <a href="http://www.appcelerator.com/platform/titanium-sdk/">Titanium</a>!</body></html>');
win.add(webView);
win.open();
@fikr4n
Copy link

fikr4n commented Mar 18, 2014

How to make it work if the link has target="_blank"?

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