title: Alter the prototype of an image tag?
body: <p>I am trying to write a library that would do the following.</p>
  
  <p>When the library is included in the head, it would alter the HTMLImageElement prototype such that any image tag that the user happened to use in their HTML or that they create dynamically in javascript would have a default onerror function that is defined by my library.</p>
  
  <p>The result of this would be that if any of the users images failed to load because they pointed to a bad url my library would handle it in a graceful way.</p>
  
  <p>I am trying the following just as an experiment, </p>
  
  <pre><code>var img = document.createElement('img');
    img.__proto__.onerror = function() {
      alert('hi');
    };
    document.body.innerHTML = '&lt;img id="foo" src="bar.png"/&gt;'
  </code></pre>
  
  <p>where the file bar.png does not exist and it does not work.</p>
  
  <p>However if I just do something like</p>
  
  <pre><code>  document.body.innerHTML = '&lt;img id="foo" src="bar.png" ' +
      'onerror="this.src = MODIT.getImage(\'blackTile\').src;"/&gt;';
  </code></pre>
  
  <p>that works fine.  Here MODIT.getImage() is a function that returns an image element.  You can play with this code here: <a href="https://mod.it/ciR_BxqJ/">https://mod.it/ciR_BxqJ/</a></p>
  
  <p>Is what I'm trying to do possible?  Alternatively is there a way to globally catch all 403 GET errors and handle them with javascript in some way?</p>
  
  <p>Thanks!</p>