Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  101] [ 2]  / answers: 1 / hits: 36090  / 15 Years ago, mon, august 10, 2009, 12:00:00

If I have a beacon:



<img src=http://example.com/beacon />


I want a method to be called once the beacon request finishes. Something like:



<script>
$(img.beacon).load(function() {
// do stuff knowing the beacon is done
});
</script>


Is it possible? Is it in jQuery?


More From » jquery

 Answers
34

Sure. Remember the load needs to be added before the src attribute.



$('<img />').load( function(){
console.log('loaded');
}).attr('src', imgUrl);


If you have defined the image tag in the markup then your stuck with when the window load event fires to be sure the image has come down the wire.


[#98943] Friday, August 7, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janeth

Total Points: 498
Total Questions: 91
Total Answers: 89

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
janeth questions
;