Trying to make my setter for innerHTML:

var oldDescr = Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML"); Object.defineProperty(Element.prototype, 'innerHTML', { set: function(htmlVal) { document.write("CATCH!"); oldDescr.set.call(this, htmlVal); } }); document.getElementById("foobar").innerHTML = "HEHE"; 

Everything works in FF 39, Chrome 43. I take examples from the Qt 5.4 bundle (browser / fancybrowser) - my setter is not called. How can I do what I want for QtWebkit?

PS: this is an ancient bug in WebKit that didn't seem to be fixed in QtWebkit: https://code.google.com/p/chromium/issues/detail?id=13175

  • You can add a link and a description of the problem, and possibly even work rounds, if any, as an answer. - Athari
  • @Discord seems to be a problem for QtWebkit. - Vladimir Martyanov
  • The bottom line is that this postscript is technically the answer for now. Unpleasant, but the answer. - Athari
  • Ah ... OK, now I’ll transfer him in response. - Vladimir Martyanov

1 answer 1

This is an ancient bug in WebKit that didn’t seem to be fixed in QtWebkit: https://code.google.com/p/chromium/issues/detail?id=13175

All other browsers for native properties. Consider these samples:

 HTMLDivElement.prototype.__lookupGetter__("innerHTML") // Firefox document.createElement("div").__lookupGetter__("innerHTML") // Firefox, Opera Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML") // IE 

None of these work in Chrome / Webkit. Only custom getters / setters can be looked up.

What steps will reproduce the problem?

Use this testcase:

 <script type="text/javascript"> alert(HTMLDivElement.prototype.__lookupGetter__("innerHTML")); </script> 

What is the expected result?

The native setter / getter function of the property.

What happens instead?

undefined is returned.