I have stumbled across this insane behavior where image.onload gets fired multiple times instead of one.
It will be too long to explain this, so here is a jsfiddle example.
When you click the first time everything seems normal, but the issue begins after the second click and with every click it just LOOPS time and time again.
The question is how to make this fire the image.onload only once per click?
You are essentially defining a new event in the
gfunction, which is called each time you click on the button.Just define it outside of the function, and everything should work as expected: http://jsfiddle.net/PP2dB/1/