【问题标题】:Open External Website/Address From Sencha Touch Application从 Sencha Touch 应用程序打开外部网站/地址
【发布时间】:2011-11-15 12:22:42
【问题描述】:

我的应用程序中有一个 ListPanel,定义如下:

            //Create List View Using ListStore Created in data.js
            SpotiPod.listPanel = new Ext.List({
                id: 'artistList',
                store: SpotiPod.ListStore,
                itemTpl: '<div>{ArtistName}</div>',
                grouped: true,
                indexBar: true,
                listeners: {
                    itemtap: function(list, index){
                        var rec = list.store.getAt(index)
                        //Ext.Msg.alert(rec.get('ArtistName'), 'Load In Spotify?', function(){location.href = rec.get('SpotifyURI');});
                        Ext.Msg.show({
                            title: rec.get('ArtistName'),
                            msg: 'Load In Spotify?',
                            buttons: Ext.MessageBox.YESNO,
                            fn: showSpotify
                            });
                        function showSpotify(btn){
                            if(btn == 'yes'){
                                window.open(rec.get('SpotifyURI'));
                            }
                        }
                    }
                }
            });

应用程序显示艺术家列表,并应使用 Spotify URI 提供指向他们的链接,当您单击“是”加载 Spotify 时,它应该打开应用程序并显示艺术家。下面的应用程序在浏览器和 iPhone 上的移动 safari 中运行良好。但是,如果我将应用程序添加到主屏幕并运行它,那么它就不再起作用了。我收到“无法显示 URL”的错误消息。

是否有人对如何更改此设置以允许正确触发链接有任何想法?

干杯

亚当

【问题讨论】:

  • 将应用程序添加到主屏幕是什么意思?
  • 正如我在移动 safari 中访问网络应用程序的地址,即 mydomain.com/mywebapp 并从那里运行到 spotify 的链接将起作用并打开 spotify 应用程序并加载正确的信息。如果我选择“添加到主屏幕”并将应用程序放在我的跳板上,那么这将停止工作。

标签: javascript iphone url sencha-touch


【解决方案1】:

这是我在 Sencha 论坛上找到的,我不知道它是否有效,如果无效,请见谅。这个想法是创建一个锚标记并模拟点击它而不是调用 window.open() 方法。这是从 sencha post 中获取的代码。

Ext.util.openLink = function(href) { 
  var link = document.createElement('a');
  link.setAttribute('href', href);
  link.setAttribute('target','_blank');
  var clickevent = document.createEvent('Event');
  clickevent.initEvent('click', true, false);
  link.dispatchEvent(clickevent);
 return false;
}

http://www.sencha.com/forum/showthread.php?130358-window.open()-from-toolbar-button-opens-window-from-list-item-a-new-tab&p=639938#post639938

【讨论】:

    猜你喜欢
    • 2012-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    • 2017-02-15
    相关资源
    最近更新 更多