Ionic:如何让我的点击事件通过

Ionic: How to let my click event go through

我创建了一个 link 并以编程方式单击它:

var a = document.createElement("a");
a.download = "mymap.png";
a.href = canvasdata;
document.body.appendChild(a);
a.click();

上面的代码块成功地触发了正常的点击,但是由于 ionic.bundle.js 中的这个函数,它会被 ionic tap 事件处理系统阻止:

function tapClickGateKeeper(e) {
    ...
    // do not allow through any click events that were not created by ionic.tap
    if ((ionic.scroll.isScrolling && ionic.tap.containsOrIsTextInput(e.target)) ||
(!e.isIonicTap && !ionic.tap.requiresNativeClick(e.target))) {
//console.log('clickPrevent', e.target.tagName);
        e.stopPropagation();

        if (!ionic.tap.isLabelWithTextInput(e.target)) {
         // labels clicks from native should not preventDefault othersize keyboard will not show on input focus
          e.preventDefault();
        }
    return false;
    }
}

如果 isIonicTap 未设置为真,此函数不允许通过点击事件。所以我自己在 Javascript 中创建的点击事件在这里也被阻止了。

如何让我的点击事件完成?

我的情况是在元素上设置属性 data-tap-disabled="true"。

我知道这个问题已经过时了,但仍然想添加我的答案。 在我的例子中,我试图从离子应用程序中保存 CSV 文件。 所以这段代码有效:

a['type'] = 'submit' ;

document.body.appendChild(link);
var e1 = document.createEvent('MouseEvents');
e1.initEvent('mousedown', true, true);
a.dispatchEvent(e1);

var e2 = document.createEvent('MouseEvents');
e2.initEvent('click', true, true);
a.dispatchEvent(e2);

document.body.removeChild(link);

此代码基于 iOnic 论坛的 this 主题。