zoukankan      html  css  js  c++  java
  • 爬虫_监控某个元素所有事件

    var DOMEvents = {
    UIEvent: "abort DOMActivate error load resize scroll select unload",
    ProgressEvent: "abort error load loadend loadstart progress progress timeout",
    Event: "abort afterprint beforeprint cached canplay canplaythrough change chargingchange chargingtimechange checking close dischargingtimechange DOMContentLoaded downloading durationchange emptied ended ended error error error error fullscreenchange fullscreenerror input invalid languagechange levelchange loadeddata loadedmetadata noupdate obsolete offline online open open orientationchange pause pointerlockchange pointerlockerror play playing ratechange readystatechange reset seeked seeking stalled submit success suspend timeupdate updateready visibilitychange volumechange waiting",
    AnimationEvent: "animationend animationiteration animationstart",
    AudioProcessingEvent: "audioprocess",
    BeforeUnloadEvent: "beforeunload",
    TimeEvent: "beginEvent endEvent repeatEvent",
    OtherEvent: "blocked complete upgradeneeded versionchange",
    FocusEvent: "blur DOMFocusIn  Unimplemented DOMFocusOut  Unimplemented focus focusin focusout",
    MouseEvent: "click contextmenu dblclick mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup show",
    SensorEvent: "compassneedscalibration Unimplemented userproximity",
    OfflineAudioCompletionEvent: "complete",
    CompositionEvent: "compositionend compositionstart compositionupdate",
    ClipboardEvent: "copy cut paste",
    DeviceLightEvent: "devicelight",
    DeviceMotionEvent: "devicemotion",
    DeviceOrientationEvent: "deviceorientation",
    DeviceProximityEvent: "deviceproximity",
    MutationNameEvent: "DOMAttributeNameChanged DOMElementNameChanged",
    MutationEvent: "DOMAttrModified DOMCharacterDataModified DOMNodeInserted DOMNodeInsertedIntoDocument DOMNodeRemoved DOMNodeRemovedFromDocument DOMSubtreeModified",
    DragEvent: "drag dragend dragenter dragleave dragover dragstart drop",
    GamepadEvent: "gamepadconnected gamepaddisconnected",
    HashChangeEvent: "hashchange",
    KeyboardEvent: "keydown keypress keyup",
    MessageEvent: "message message message message",
    PageTransitionEvent: "pagehide pageshow",
    PopStateEvent: "popstate",
    StorageEvent: "storage",
    SVGEvent: "SVGAbort SVGError SVGLoad SVGResize SVGScroll SVGUnload",
    SVGZoomEvent: "SVGZoom",
    TouchEvent: "touchcancel touchend touchenter touchleave touchmove touchstart",
    TransitionEvent: "transitionend",
    WheelEvent: "wheel"
    }
    
    var RecentlyLoggedDOMEventTypes = {};
    
    for(DOMEvent in DOMEvents){
    
      var DOMEventTypes = DOMEvents[DOMEvent].split(' ');
    
      DOMEventTypes.filter(function(DOMEventType){
        var DOMEventCategory = DOMEvent + ' '+DOMEventType;  
        document.addEventListener(DOMEventType, function(e){    //此例子是监控document的所有元素,实际用途中可只监控某个元素
          if(RecentlyLoggedDOMEventTypes[DOMEventCategory]) return;
          RecentlyLoggedDOMEventTypes[DOMEventCategory] = true;
          setTimeout(function(){ RecentlyLoggedDOMEventTypes[DOMEventCategory] = false }, 5000);
          var isActive = e.target==document.activeElement;
          if(isActive) {
            console.info(DOMEventCategory, 
              ' target=', e.target, 
              ' active=', document.activeElement, 
              ' isActive=', true );
          } else {
            console.log(DOMEventCategory, 
              ' target=', e.target,
              ' active=', document.activeElement, 
              ' isActive=', false );
          }
    
        }, true);
      });
    
    }

    此段代码是在浏览器的console中执行

  • 相关阅读:
    UVA
    剑指offer 面试题11
    SharePoint 2013+ Sqlserver 2014 Kerberos 配置传奇, 最终的解决方案 验证。
    ASC(1)G(上升时间最长的序列)
    J2EE它是一个框架?平台?规范?
    C++和python使用struct传输二进制数据结构来实现
    前端开发面试题集(二)
    C语言中<CR>是什么意思
    Delphi ParamStr 使用方法
    打包工具 使用帮助 inno setup
  • 原文地址:https://www.cnblogs.com/gisblogs/p/5368204.html
Copyright © 2011-2022 走看看