有时候内容直接从后台获取,有可能包含超链接,打包成应用之后,点击会造成不好的后果,这样做能够用外部浏览器打开。需要Cordova支持
监听插件代码:
1 /*
2 *监听a标签,用外部浏览器打开链接
3 */
4 Ext.define('ux.ConHref', {
5 alias: 'plugin.conHref',
6 xtype: 'conHref',
7 config: {
8 cmp: null,
9 //竖向滚动,不显示滚动条
10 scrollable: {
11 direction: 'vertical',
12 directionLock: true,
13 indicators: false
14 }
15 },
16 constructor: function (config) {
17 this.initConfig(config);
18 this.callParent([config]);
19 },
20 //初始化
21 init: function (cmp) {
22 this.setCmp(cmp);
23 },
24 //更新配置
25 updateCmp: function (newCmp, oldCmp) {
26 if (newCmp) {
27 newCmp.element.on({
28 tap: 'onTap',
29 delegate: 'a',
30 scope: this
31 });
32 newCmp.setScrollable(this.getScrollable());
33 }
34 },
35 //用外部浏览器打开链接
36 onTap: function (e, b) {
37 var a = e.getTarget('a');
38 if (a) {
39 a.onclick = function () {
40 return false;
41 }
42 window.open(a.href, '_system');
43 }
44 }
45 });
使用代码:
1 Ext.define('app.view.panel.Href', {
2 alternateClassName: 'panelHref',
3 extend: 'Ext.Container',
4 xtype: 'panelHref',
5 requires: ['ux.ConHref'],
6 config: {
7 cls:'info',
8 title: '内容包含超链接',
9 plugins: 'conHref',
10 scrollable:null,
11 html: '<a href="http://www.google.com.hk/">谷歌</a><br/><br/>有时候内容直接从后台获取,有可能包含超链接,打包成应用之后,点击会造成不好的后果,这样做能够用外部浏览器打开。需要Cordova支持'
12 }
13 });
效果: