10 examples of 'document attachevent' in JavaScript

Every line of 'document attachevent' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
551doc.addEventListener("DOMContentLoaded", function DOMContentLoaded(){
552 // remove the listener itself
553 doc.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
554 // assign readyState as complete
555 doc.readyState = "complete";
556}, false);
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

23public static addEventListener(eventName: string, cb: any, flag: boolean): void {
24 let listeners = this.events[eventName];
25 if (!listeners) {
26 listeners = [];
27 this.events[eventName] = listeners;
28 }
29
30 listeners.push(cb);
31}
70function detach() {
71 SUPPORT_CLONED_EVENTS = true;
72
73 div.detachEvent('onclick', detach);
74}
78function addEvent(on, fn, self){
79 return (self = this).attachEvent('on' + on, function(e){
80 var e = e || win.event;
81 e.preventDefault = e.preventDefault || function(){e.returnValue = false;};
82 e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true;};
83 fn.call(self, e);
84 });
85}
20export function addEventListener(receiver, eventName, fn) {
21 if (receiver.addEventListener) {
22 return receiver.addEventListener(eventName, fn);
23 } else if (receiver.attachEvent) {
24 return receiver.attachEvent('on' + eventName, fn);
25 }
26}
31function addEventListener(element, event, handler) {
32 if (element.addEventListener) {
33 return element.addEventListener(event, handler, false);
34 }
35 if (element.attachEvent) {
36 return element.attachEvent('on' + event, function () { handler.call(element); });
37 }
38}
104_attachEvent: function _attachEvent(eventNames) {
105
106 if (!Array.isArray(eventNames)) {
107 // Transform the string into an array if it isn't already.
108 eventNames = [eventNames];
109 }
110
111 // Iterate over each of the event types for the current node.
112 for (var eventIndex = 0, maxEvents = eventNames.length; eventIndex < maxEvents; eventIndex++) {
113
114 var eventName = eventNames[eventIndex];
115
116 if (typeof this.node[eventName] === 'undefined') {
117
118 // Throw an exception if we're unable to find the specified event.
119 throw 'MEMORIA: Unable to find the `' + eventName + '` event on `' +
120 this.node.nodeName.toLowerCase() +'` node.';
121
122 }
123
124 // Attach the event to the `_save` method.
125 this.node[eventName] = this._save.bind(this);
126
127 }
128
129},
24window.addEventListener = Window.prototype.addEventListener = HTMLDocument.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener(type, listener) {
25 var element = this;
26 if (!element._events) {
27 element._events = {};
28 }
29 if (!element._events[type]) {
30 element._events[type] = function(event) {
31 var list = element._events[event.type].list, events = Array.prototype.concat.call([], list), index = 0, pointer;
32 event.preventDefault = function preventDefault() {
33 if (event.cancelable !== false) {
34 event.returnValue = false;
35 }
36 };
37 event.stopPropagation = function stopPropagation() {
38 event.cancelBubble = true;
39 };
40 event.stopImmediatePropagation = function stopImmediatePropagation() {
41 event.cancelBubble = true;
42 event.cancelImmediate = true;
43 };
44 event.currentTarget = element;
45 event.relatedTarget = event.fromElement || null;
46 event.target = event.srcElement || element;
47 event.timeStamp = new Date().getTime();
48 if (event.clientX) {
49 event.pageX = event.clientX + document.documentElement.scrollLeft;
50 event.pageY = event.clientY + document.documentElement.scrollTop;
51 }
52 for (;(pointer = events[index]) !== undefined && !event.cancelImmediate; ++index) {
53 if (list.indexOf(pointer) > -1) {
54 pointer.call(element, event);
55 }
56 }
57 };
58 element._events[type].list = [];
59 element.attachEvent && element.attachEvent("on" + type, element._events[type]);
60 }
61 element._events[type].list.push(listener);
62};
126export function on(element, type, listener) {
127 if (type === event.INPUT) {
128 addInputListener(element, listener)
129 }
130 else if (type === event.CHANGE && isBox(element)) {
131 addChangeListener(element, listener)
132 }
133 else {
134 element.attachEvent(`on${type}`, listener)
135 }
136}
173addEventListener: function addEventListener(element, event, callback) {
174 if (element.addEventListener) return element.addEventListener(event, callback);
175
176 element.attachEvent("on" + event, callback);
177}

Related snippets