7

In my Sencha Touch 2 application I need to handle redirection events on my own. By this I mean I need to be able to handle a href events and do the redirection myself.

I'm using the following code:

Ext.Viewport.element.addListener("tap", function(e) {
    e.stopEvent();
    e.stopPropagation();
    e.preventDefault();
    var href = e.target.getAttribute("href");
    // ... my code ...
}, this, {delegate: "a"});

By none of the above mentioned functions work (stopEvent, stopPropagation, preventDefault). The application always opens the link in my app web view.

Is here any possible way to disable a href opening links?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pavel Stupka
  • 213
  • 2
  • 14

1 Answers1

12

I usually do this this way :

Ext.Viewport.element.dom.addEventListener('click', function (e) {
    if (e.target.tagName !== 'A') {
        return;
    };
    e.preventDefault();
    var href = e.target.getAttribute('href');
}, false);

Try here

Hope this helped

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
  • 1
    Nice, this solved my issue too. Am willing to lose stackoverflow reputation points for saying Sencha Touch 2.2.1 as of 8/13/2013 is not documented that well. This was just one of the many slew of issues I'm facing during an upgrade project. Kinda' reminds me of IE. #endrant. – Code Monkey Aug 13 '13 at 18:47