【发布时间】:2014-10-31 10:21:28
【问题描述】:
我有一个简单的 Titanium 应用程序,它打开一个 web 视图并加载一个 URL。我希望链接在默认浏览器中打开,而不是在应用程序中打开。
我有一些 jQuery 代码向页面中的所有链接添加点击事件。
<script>
jQuery('a').click(function() {
console.log("Handler for .click() called for URL: " + this.href);
Ti.App.fireEvent('ynOpenURL', {url: this.href });
});
在我的 app.js 文件中:
var win = Ti.UI.createWindow();
var mywebview = Ti.UI.createWebView({
url : 'http://xxxx.xxxxx.com/',
enableZoomControls: false
});
win.add(mywebview);
win.open();
Ti.App.addEventListener('ynOpenURL', function(e) {
Ti.API.info('yyyyyy');
Ti.API.info(e.url);
if (Ti.Platform.canOpenURL(e.url)){
Ti.Platform.openURL(e.url);
} else {
alert("Cannot open URL");
}
当我在我的 Android (4.4) 上运行该应用程序时,网页会正确加载。
当我点击手机上的链接时,我会在控制台中看到以下内容:
Handler for .click() called for URL: http://xxx.xxxxx.xxx/
Uncaught TypeError: Cannot read property 'App' of undefined (xxxx)
不记录任何 Titanium 控制台事件,只记录网页中的 javascript 事件。
【问题讨论】:
-
从哪里加载 webview 部分,远程服务器 url 或 app 内的 html 文件?
-
webview 正在加载远程 URL
标签: javascript android jquery titanium appcelerator