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

Ionic: How to let my click event go through

本文关键字:事件 我的 Ionic      更新时间:2023-09-26

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

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

上面的代码块成功地正常触发了一次点击,但由于ionic.bundle.js:中的此功能,它将被离子点击事件处理系统阻止

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未设置为true,则此函数不允许直通单击事件。因此,我自己在Javascript中创建的点击事件在这里也被阻止了。

如何让我的点击事件通过?

我的情况是在元素上设置属性数据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论坛上的这个帖子。