Appcelerator Titanium -在移动应用程序中打开一个网站

Appcelerator Titanium - Opening a website within a mobile app

本文关键字:网站 一个 Titanium 移动 应用程序 Appcelerator      更新时间:2023-09-26

我试图打开一个网站上的按钮点击从我的应用程序。它只是一个简单的帮助按钮,应该打开网站的帮助页面。不要太花哨。但我在装枪上遇到了很多麻烦。

下面是我的相关代码:

var helpButton = $.help;
var webview = Titanium.UI.createWebView(URL_HELP);
helpButton.addEventListener('click', function() {
    try {
        var helpWin = Titanium.UI.createWindow();
        helpWin.add(webview);
        helpWin.open({modal:true});
    } catch (e) {
        Ti.API.error("Error: " + e);
    }
});

错误也永远不会被捕获。在单击按钮时,它会加载一个新窗口,但会一直加载下去。我不知道问题出在哪里,也不知道该怎么办。

请帮忙,如果你有任何其他问题或想法,请告诉我。

首先尝试创建webview,将其属性设置为所需值。下面的代码对我来说很好。

var webview = Titanium.UI.createWebView({
    url: 'http://stackoverflow.com/tour',
    top: 0,
    left: 0,
    width: "100%",
    height: "100%"
});

你可以用你的url试试。

注意:如果你只想显示帮助页面,你可以在帮助按钮点击事件中创建窗口后创建它,而不是创建全局的webview。代码应该是这样的。您也可以使用$.help。addEventListener,而不是把它赋值给一个单独的变量。

$.help.addEventListener('click', function() {
    try {
        var helpWin = Titanium.UI.createWindow();
        var webview = Titanium.UI.createWebView({
            url: URL_HELP,
            top: 0,
            left: 0,
            width: "100%",
            height: "100%"
        });
        helpWin.add(webview);
        helpWin.open({modal:true});
    } catch (e) {
        Ti.API.error("Error: " + e);
    }
});