Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with FF 26 after chaging src atr. of an image #121

Closed
individual-it opened this issue Jan 20, 2014 · 10 comments
Closed

Problems with FF 26 after chaging src atr. of an image #121

individual-it opened this issue Jan 20, 2014 · 10 comments

Comments

@individual-it
Copy link

In my application I have to exchange an image constantly with a new one (webcam).
So I have 2 img tags. While one image is shown the other is loaded. As soon the second image is loaded the first one is hidden and the second one is shown. Then again the first one gets a new src= and loads a new image. As soon as it finished it gets shown.
I'm using this plugin to see if the new image is loaded before I hide the first one and show the second one.

$('#imageFrame1_' + newImage).attr( "src", data.responseText );
var imgLoad = imagesLoaded( '#imageFrame1_' + newImage);
imgLoad.on( 'always', function( instance ) {
console.log('#imageFrame1_' + newImage + ' loaded ' + Date.now());
$('#imageFrame1_' + newImage).show();
$('#imageFrame1_' + currentImage).hide();
//more code here
}); 

the first time an image is loades "imgLoad.on" is fired correctly after the image loading is finished. But when I change the src, its fired immediately without waiting for the new image to be loaded.

This happens with Firefox 26.0 on Linux. Chrome works as it should.

@tremby
Copy link

tremby commented Feb 7, 2014

I'm having the same problem.

@Hiswe
Copy link

Hiswe commented Apr 24, 2014

I have the same problem on firefox 28 replacing a dummy src (base64 encoded blank gif) with the real real src.

@Kris-B
Copy link

Kris-B commented Sep 19, 2014

I'm having the same issue with FF30...
@tremby @Hiswe @individual-it -> did you find any workaround?

@Hiswe
Copy link

Hiswe commented Sep 25, 2014

Just changing the source was not enough.
So I have just replace the tag by a clone with the new source… And it's working as expected.

@Kris-B
Copy link

Kris-B commented Sep 25, 2014

@Hiswe - thanks for your feedback!
In the meantime I found another workaround: set the src to "" before setting the new url.

@Kris-B
Copy link

Kris-B commented Sep 25, 2014

BTW: this is not an imagesloaded issue, but usage of imagesloaded can be impacted by this FF issue...

@tremby
Copy link

tremby commented Sep 25, 2014

Honestly I don't even remember which project I was working on when I hit this issue. Grepping my source base is inconclusive -- I may have set the src to the empty string as Kris-B suggests above, or I may have switched to a homegrown solution.

@0xadri
Copy link

0xadri commented Nov 20, 2014

@Kris-B Your workaround works perfectly in Firefox 33 !

Live demos showing Kris-B's solution:

If you test both solutions on Firefox, you will see the "done" message appearing in the console: too early when NOT using your workaround, & just when expected when using it.

Things to note about the tests I have done:

  • I have only tested on Firefox on Windows 7 for desktop
  • I have only tested the always() event (not the others)

Conclusion

Until the workaround found by Kris-B is fully tested, you're probably "safer" by using imagesLoaded only on newly added images element.

@Kris-B
Copy link

Kris-B commented Nov 26, 2014

thanks for your feedback @adrien-be ;-)

@tilt-me
Copy link

tilt-me commented Feb 12, 2017

@Kris-B
Be careful, setting the src of an image to an empty string can be dangerous for performance reasons:
Empty image src can destroy your site

Don't know if it is still an issue for modern browsers, but I would avoid it anyway ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants