I'm dynamically adding content to HTML where there are images. By design I don't know the actual image data on the time of adding the content, but I'm retrieving this data using JS. I need an event that triggers the function that retrieves this content. So far I've implemented this using a hack:
<img src="_" onerror="loadImage(this)" data-id="1"/>
<img src="_" onerror="loadImage(this)" data-id="2"/>
<img src="_" onerror="loadImage(this)" data-id="3"/>
Each image fails to load src="_"
attribute and triggers the onerror
handle.
My question is how to avoid triggering the onerror
event and call the loadImage
by a more appropriate event. I'm looking for an event of each individual img
.
Update: don't consider that as an easy question. The images are added dynamically from C++ code into QWebView. There are no actual images that I can access using any URL, but I'm retrieving them as byte arrays from the database (from C++ code as well). I'm accessing the C++ code from the JS function loadImage
. I cannot use the window.onload
cause the image is added at random moments of time when the main page is already loaded.