8 examples of 'img onerror' in JavaScript

Every line of 'img onerror' 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
85function imgerrorfun(imgobj,imgSrc){
86 setTimeout(function(){
87 imgobj.src=imgSrc;
88 },1000*5);
89 }
54_onError (e) {
55 this._error = true;
56 // WARNING: we modify the exposed property "skeleton" from the inside
57 this.skeleton = false;
58}
172function onError(error) {
173 if (error && error.data) {
174 throw error;
175 } else {
176 throw gettext('Unable to create the image.');
177 }
178}
22function error() {
23 setImg(imgIO.element, task.snapshot.downloadURL); // actually success
24 // imgIO.empty = true;
25 // setImg(imgIO.element, imgIO.default);
26 // alert('Error uploading image.');
27}
117function onXhrError(callback: ImgLoadCallback, imgData: ImgData, err: ErrorEvent) {
118 // darn, we got an error!
119 callback && callback(0, (err.message || ''), null);
120 imgData.xhr = null;
121}
101function imgLoaded( img, isBroken ) {
102 // don't proceed if BLANK image, or image is already loaded
103 if ( img.src === BLANK || jQuery.inArray( img, loaded ) !== -1 ) {
104 return;
105 }
106
107 // store element in loaded images array
108 loaded.push( img );
109
110 // keep track of broken and properly loaded images
111 if ( isBroken ) {
112 broken.push( img );
113 } else {
114 proper.push( img );
115 }
116
117 // cache image and its state for future calls
118 jQuery.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } );
119
120 // trigger deferred progress method if present
121 if ( hasNotify ) {
122 deferred.notifyWith( jQuery(img), [ isBroken, $images, jQuery(proper), jQuery(broken) ] );
123 }
124
125 // call doneLoading and clean listeners if all images are loaded
126 if ( $images.length === loaded.length ){
127 setTimeout( doneLoading );
128 $images.unbind( '.imagesLoaded' );
129 }
130}
387function imgLoaded( img, isBroken ) {
388 // don't proceed if BLANK image, or image is already loaded
389 if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) {
390 return;
391 }
392
393 // store element in loaded images array
394 loaded.push( img );
395
396 // keep track of broken and properly loaded images
397 if ( isBroken ) {
398 broken.push( img );
399 } else {
400 proper.push( img );
401 }
402
403 // cache image and its state for future calls
404 $.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } );
405
406 // trigger deferred progress method if present
407 if ( hasNotify ) {
408 deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] );
409 }
410
411 // call doneLoading and clean listeners if all images are loaded
412 if ( $images.length === loaded.length ) {
413 setTimeout( doneLoading );
414 $images.unbind( '.imagesLoaded', imgLoadedHandler );
415 }
416}
117self.imageElement.onerror = function onImgError() {
118 self.me.classList.add('error');
119}

Related snippets