Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sencha Touch 2 - prevent a-href events (a-href event handling)

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?

like image 985
Pavel Stupka Avatar asked Nov 26 '12 09:11

Pavel Stupka


1 Answers

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

like image 121
Titouan de Bailleul Avatar answered Nov 11 '22 10:11

Titouan de Bailleul