Newton
Newton

Reputation: 245

.load(function) firing twice

I have a click event that loads an iframe, which is followed by a .load(function() for the iframe. The problem is the load function gets fired twice for each click event. Can someone explain me the reason why this is happening? And how can it be prevented?

$(document).ready(function() {
    $('.Popup').click(function() {
        $('#myiframe').attr('src', $(this).attr('href')).load(function() {
            alert('done loading')
        })
        return false;
    });
});​

Upvotes: 3

Views: 2734

Answers (1)

Jay Tomten
Jay Tomten

Reputation: 1717

The load event will fire when the iframe is created, then again when the src is set. The load event is pretty sketchy across different browsers so definitely do plenty of testing.

Upvotes: 5

Related Questions