Ti.App.fireEvent不工作;错误遗漏的类型错误:无法读取的未定义的属性'应用' [英] Ti.App.fireEvent not working; error Uncaught TypeError: Cannot read property 'App' of undefined

查看:360
本文介绍了Ti.App.fireEvent不工作;错误遗漏的类型错误:无法读取的未定义的属性'应用'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这将打开一个网页视图,并加载一个URL一个简单钛的应用程序。我想的链接打开在默认浏览器,而不是应用程序。

I have a simple Titanium app which opens a webview, and loads a URL. I want the links to open in the default browser, not the app.

我有一些jQuery code增加了一个click事件在页面中的所有链接。

I have some jQuery code which adds a click event to all links in the page.

<script>
jQuery('a').click(function() {
    console.log("Handler for .click() called for URL: " + this.href);
    Ti.App.fireEvent('ynOpenURL', {url:  this.href });
});

在app.js文件中我有:

In the app.js file I have:

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");
 }

当我在我的Andr​​oid(4.4)的网页加载正确运行的应用程序。

When I run the app on my Android (4.4) the web page loads correctly.

当我点击了电话,我得到在控制台下面的链接:

When I click a link on the phone I get the following in the console:

Handler for .click() called for URL: http://xxx.xxxxx.xxx/
Uncaught TypeError: Cannot read property 'App' of undefined (xxxx)

钛控制台的事件没有被记录,只是在网页中JavaScript事件。

None of the Titanium console events are logged, only the javascript events in the webpage.

推荐答案

正如你所提到的web视图加载远程URL。因此, 钛。* 钛。* 不可用在远程服务器

As you mentioned that the webview is loading remote url. So Ti.* or Titanium.* are not available at your remote server.

你可以做的是:


  • 创建应用程序内的HTML文件,并通过AJAX加载数据,并使用 fireEvent

  • 通过钛http客户端加载数据,并使用 Ti.Platform.openURL 相应。

  • Create a html file within the app and load the data via ajax and use fireEvent.
  • Load the data via titanium http client and use Ti.Platform.openURL accordingly.

编辑: 报价钛的WebView文档

远程脚本

从远程Web服务器上下载的脚本无法访问钛的命名空间。

Scripts downloaded from remote web servers cannot access the Titanium namespace.

要与远程内容交互,等到加载内容,然后使用evalJS方法来执行网络视图内的JavaScript的前pression和检索的前pression的价值。

To interact with remote content, wait until the content is loaded, then use the evalJS method to execute a JavaScript expression inside the web view and retrieve the value of an expression.

这篇关于Ti.App.fireEvent不工作;错误遗漏的类型错误:无法读取的未定义的属性'应用'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆