Note that there are some explanatory texts on larger screens.

plurals
  1. POFailure to override Element's addEventListener in Firefox
    primarykey
    data
    text
    <p>I'm trying to override the Element object's <code>addEventListener</code> method, in a cross-browser manner. The purpose is so that I can load some 3rd party scripts asynchronously, and those scripts call this method prematurely. </p> <p>I created an HTML file that works perfectly in Chrome, but on Firefox I get this exception:</p> <blockquote> <p>"Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" </p> </blockquote> <p>If you comment out the lines in the file that change the INSTANCE methods, it works. But I need to do it on the "class type" (i.e. prototype). </p> <p>Any suggestions would be appreciated.</p> <p>Thanks, Guypo</p> <p>Here's the file I created</p> <pre><code>&lt;html&gt;&lt;body&gt; &lt;img id="testImg" src="http://www.blaze.io/wp-content/themes/Blaze/images/header_logoB.png"&gt; &lt;script&gt; function myLog(msg) { "undefined" != typeof(console) &amp;&amp; console.log("Log: " + msg); } function customListener(type, event, useCapture) { // Register the event myLog('Registering event'); this._origListener.apply(this, arguments); } // Also tried HTMLImageElement Element.prototype._origListener = Element.prototype.addEventListener; Element.prototype.addEventListener = customListener; var img = document.getElementById("testImg"); // Uncommenting these lines works - but in the real case I can't access these objects //img._origListener = img.addEventListener; //img.addEventListener = customListener; img.addEventListener('load',function() { myLog('load callback'); }, false); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload