在themeablebrowser Cordova / Phonegap中获取页面标题

时间:2015-03-31 10:29:43

标签: javascript android cordova cordova-plugins

您好我在Cordova v3.7和themeablebrowser Cordova plugin工作 想要获得themeablebrowser页面的标题,我无法得到它。我已尝试过文档中指定的executeScript但应用程序崩溃了。这是我到目前为止所做的。

function innAppInit(_url) {
    app.Log('browser news link=' + _url);
    if (_url == null) {
        _url = 'http://apache.org';
    }
    var ref = cordova.ThemeableBrowser.open(_url, '_blank', {

        backButtonCanClose: false,
        hideForwardButton: true,
        toolbarColor: '#239EC9',
        titleColor: '#FFFFFF',
        statusbarColor: '#239EC9',
        navButtonAlign: 'left',
        closeButtonAlign: 'right',
        menuButtonAlign: 'right',
        titleStaticText: 'Add New Web Page',

        menuButtonImage: 'themeablebrowser_stub_menu',
        menuButtonPressedImage: 'themeablebrowser_stub_menu_highlight',
        closeButtonImage: 'themeablebrowser_stub_close',
        closeButtonPressedImage: 'themeablebrowser_stub_close_highlight',
        backButtonImage: 'themeablebrowser_stub_back',
        backButtonPressedImage: 'themeablebrowser_stub_back_highlight',
        // menuTitle: 'Add Url to list',
        menuCancel: 'Cancel',
        menuItems: [{
            event: 'event_getURL',
            label: 'Add'
        }]
    }); 

    ref.addEventListener('loadstart', function(event) {
        try {
            app.Log('loadstart function');
            $('.ui-loader').show();

        } catch (e) {
            app.ErrorLog(e);
        }
    });
    ref.addEventListener('loadstop', function(event) {
        try {
            app.Log('loadstop function');
            $('.ui-loader').hide();


             ref.executeScript({
                    code: 'return document.title'
                },
                function(values) {
                    alert(values);                       
                });

        } catch (e) {
            app.ErrorLog(e);
        }
    });
    ref.addEventListener('event_getURL', function(event) {
        try {

            var url = event.url;
            app.Log('get url=' + url);          
            ref.close();

        } catch (e) {
            app.ErrorLog(e);
        }
    });
    ref.addEventListener('exit', function(event) {
        try {
            app.Log('exit function');            

            $('.ui-loader').hide();

        } catch (e) {
            app.ErrorLog(e);
        }
    });
}

1 个答案:

答案 0 :(得分:2)

此问题已在bug跟踪器中提出并进行了讨论。 https://github.com/initialxy/cordova-plugin-themeablebrowser/issues/8

要点是你执行的脚本应该是

document.title

return document.title