Created
September 29, 2012 17:53
-
-
Save mogya/3804712 to your computer and use it in GitHub Desktop.
[titanium] webview which open any url on the web browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to make it work if the link has
target="_blank"
?