score:3

Accepted answer

See related: Is it possible to listen image load event in SVG?

I couldn't get the native addEventListener approach to work, but it looks like you can just set the onload attribute (works in Chrome, at least):

svg.append("image")
    .attr('onload', function() {
         alert('loaded');
    })
    .attr("xlink:href", mainscreenURL);

See fiddle: http://jsfiddle.net/dKxH9/

score:0

@nrabinowitz, your code doesn't work as it was planned.

Using .attr('onload', function() {}) calls function during assigning 'onload' attribute, not during onload event.

Proper implementation should be as follows (see http://jsfiddle.net/L83nag59/)

svg.append("image")
.on('load', function() {
     alert('loaded');
})
.attr("xlink:href", mainscreenURL)

Unfortunately, it doesn't work in IE11.


Related Query

More Query from same tag