I'm working on a chrome extension business gamification system that tracks users across various web applications, and tracks their progress within the applications to determine a user ranking in their workplace.

我正在开发一个Chrome扩展业务游戏化系统,该系统可以跟踪各种Web应用程序中的用户,并跟踪他们在应用程序中的进度,以确定用户在其工作场所中的排名。

I know you can track which elements are created, using something like:

我知道您可以使用以下内容跟踪创建的元素:

window.addEventListener('DOMNodeInserted', function(e){
  console.log(e.target);
}, false);

But as this can be quite slow (noticeable lag within complex web applications), I would like to only detect elements that are created as a result of mouse clicks (on an element, for example).

但由于这可能非常慢(复杂的Web应用程序中明显滞后),我只想检测因鼠标点击而产生的元素(例如,在元素上)。

I just tested this, locally:

我刚在本地测试了这个:

<!DOCTYPE html>
<html>
<body>

    <div id="creator">Click me</div>

    <script>

        var click_event = 0;

        function add_element(e)
        {
            console.log(e);
            click_event = e;
            var div = document.createElement('div');
            div.innerHTML = "created";
            document.body.appendChild(div);
        }

        function element_created(e)
        {
            console.log(e);
            if(e == click_event)
            {
                console.log("SAME EVENT");
            }
        }

        document.getElementById('creator').addEventListener('click', add_element, false);
        window.addEventListener('DOMNodeInserted', element_created, false);

    </script>

</body>
</html>

in the hope that the events would be the same, or that upon inspecting the DOMNodeInserted event, I'd find some way of extracting the original click event from the insertion event's properties. I found nothing within the properties of the insertion event that linked it to the click event, though.

希望事件是相同的,或者在检查DOMNodeInserted事件时,我会找到一些从插入事件的属性中提取原始click事件的方法。但是,我在插件事件的属性中找不到任何内容,它将它与click事件相关联。

Is there any way of finding which event triggered a DOMNodeInserted event using JavaScript?

有没有办法找到哪个事件使用JavaScript触发了DOMNodeInserted事件?

1 个解决方案

#1


0

Use custom event when you are inserting elements from javascript, but only based on event "DOMNodeInserted", it impossible, still you can use a custom attribute on element <div insertedwith="click"> and check on "DOMNodeInserted" handler if e.target has that attribute. Anyway check the example, hope will help you.

当您从javascript插入元素时使用自定义事件,但仅基于事件“DOMNodeInserted”,这是不可能的,您仍然可以在元素

上使用自定义属性,并检查“DOMNodeInserted”处理程序(如果e)。 target具有该属性。无论如何检查示例,希望对您有所帮助。

更多相关文章

  1. 为什么elementFromPoint()在IE 11上的iframe中使用时不返回DOM元素
  2. jqGrid 数据加载完事件 loadComplete 使用
  3. Jquery中动态添加元素的绑定事件不起作用
  4. 有没有办法检查两个数组是否具有相同的元素?
  5. 如何从json对象获取匹配元素的索引?
  6. 我可以使用onBlur事件对TextBox进行日期检查吗?
  7. jQuery:添加事件监听器是否覆盖相同事件的前一个监听器?
  8. 为什么我不能删除数组的元素?
  9. jQuery插件:如何将元素引用传递给回调函数?

随机推荐

  1. mysql 中使用聚合函数sum()后出现很长的
  2. mysql学习--1.事务
  3. 获取喜欢和评论的帖子 - 一个查询?
  4. MySQL修改表结构操作命令总结
  5. error while loading shared libraries:
  6. mysql事务的默认隔离级别
  7. Linux安装MySQL的两种方法 先卸载之前版
  8. Mysql5.7下的三种循环
  9. Mysql存储过程、索引
  10. MySQL查询时有时候需要某条记录置顶或者