是否有可能以编程方式赶在浏览器网页上的所有事件? [英] Is it possible to programmatically catch all events on the page in the browser?

查看:120
本文介绍了是否有可能以编程方式赶在浏览器网页上的所有事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这里是由W3C标准定义的事件的列表。 (这个列表是基于HTML5标准中定义的一个OnEvent属性。我认为还有许多其他事件类型,但是这个名单足够长,因为它是。)

First of all, here is a list of event types that are defined by the W3C standards. (This list is based on the onevent attributes defined in the HTML5 standard. I assume that there are dozens of other event types, but this list is long enough as it is.)


  • 中止

  • 打印后

  • beforeprint

  • beforeunload

  • 模糊

  • canplay

  • canplaythrough

  • 更改

  • 点击

  • 文本菜单

  • 复制

  • cuechange

  • 剪切

  • DBLCLICK

  • DOMContentLoaded


  • dragend

  • 的dragenter

  • dragleave

  • 的dragover

  • 的dragstart


  • durationchange

  • 清空

  • 结束

  • 错误

  • 焦点

  • 的focusIn

  • 事件的内容

  • formchange

  • 的formInput

  • hashchange

  • 输入

  • 无效

  • 的keydown

  • 键preSS

  • KEYUP

  • 负荷

  • loadeddata
  • 等待load​​edmetadata
  • loadstart

  • 的消息

  • 鼠标按下

  • 的mouseenter

  • 鼠标离开

  • 鼠标移动

  • 鼠标移开

  • 鼠标悬停

  • 鼠标松开

  • 滚轮

  • 离线

  • 在线

  • pagehide

  • pageshow

  • 粘贴

  • 暂停

  • 游戏

  • 播放

  • popstate

  • 进步

  • ratechange

  • readystatechange

  • 重做

  • 重置

  • 调整

  • 滚动

  • seeked


  • 选择

  • 显示

  • 熄火

  • 存储

  • 提交

  • 暂停

  • timeupdate

  • 撤消

  • 卸载

  • volumechange


现在,是有可能定义一个全局事件处理程序的任何事件发生最初的任何页面上的元素被称为? (在这种情况下,我并不想算,因为他们从后代元素冒泡发生上的元素这些事件 - 这就是为什么我写了原来发生)

Now, is it possible to define a global event handler that is called when any event originally occurs on any element on the page? (In this case, I don't want to count those events that occurred on elements because they bubbled up from a descendant element - that's why I wrote "originally occurs".)

如果这是不可能的,是它至少可以定义的事件处理函数被调用时的任何事件冒泡到DOM树的根(这是可以的文件对象或窗口对象 - 无论是应工作)? (我知道,它可能停止编程冒泡,但我会用这个事件处理程序,对任何其他元素没有定义其他处理程序在页面上。)(另外,我相信一些事件不冒泡,但是让我们忽略这些案件这个参数的缘故)。

If that is not possible, is it at least possible to define an event handler that is called when any event bubbles up to the root of the DOM tree (which is either the document object or the window object - both should work)? (I know that it's possible to stop bubbling programmatically, but I would use this event handler on a page that has no other handlers defined on any other elements.) (Also, I believe some events don't bubble up, but let's ignore these cases for the sake of this argument.)

我知道我可以做到这一点(使用jQuery):

I know that I can do this (using jQuery):

$(document).bind('abort afterprint beforeprint beforeunload etc.', function() {
    // handle event
});

但是这将是对我来说是相当不可取的解决方案。

but that would be a rather undesirable solution for me.

顺便说一句我并不需要跨浏览器的解决方案。如果它工作在短短的一个浏览器,我没事。

btw I don't need a cross-browser solution. If it works in just one browser, I'm fine.

此外,<一个href=\"http://stackoverflow.com/questions/4089516/view-javascript-events-in-browser/4089542#4089542\">Firebug能够记录事件,但我希望能够(通过JavaScript),而不是让他们只需在控制台登录编程赶上事件。

Also, Firebug is able to log events, but I would like to be able to catch the event programmatically (via JavaScript) rather then having them simply logged in the console.

推荐答案

我高度怀疑有办法在Firefox中做到这一点。看着 Firebug的来源$ C ​​$ C (特别是 attachAllListeners 法),事实证明,通过事件名称的列表迭代显然是要走的路,但是这并没有解决问题,冒泡

I highly doubt there's a way to do this in Firefox. Looking at Firebug's source code (particularly the attachAllListeners method), turns out that iterating through a list of event names is obviously the way to go, but this doesn't solve the bubbling issues.

这篇关于是否有可能以编程方式赶在浏览器网页上的所有事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆