Just trying to crate a simple comment form on a blog. I want to load the user's gravatar (using jQuery) when he/she writes this in the email box.
How can I do that?
Just trying to crate a simple comment form on a blog. I want to load the user's gravatar (using jQuery) when he/she writes this in the email box.
How can I do that?
Wow thanks for this post. But if in case you have your own blank image and you want to use it instead of the gravatar.
The gravatar url looks like this:
Here are the rest of the options for the URL.
So all you're going to have to do is include a function called md5 that returns the md5 hash of the user's email. There are many online that do this, but I believe https://github.com/blueimp/JavaScript-MD5/blob/master/README.md works well. After that, just do:
I thought this was obvious, but I will add it for posterity's sake:
If user emails are private and you're showing this ala-stackoverflow in a listing, you are probably better off encoding the email on the server so that user emails are not publicly visible if you look at the source.
check out my fiddle providing the function
Only providing the email is mandatory - the rest uses default values.
Be sure to also include the de-facto-standard MD5-generator JS file from Joseph Myers with
The tricky part is generating the URL using an MD5 hash implementation, which is separate from jQuery. I found that the blueimp-md5 library has the most stars of the various MD5 packages on GitHub, and it's pretty much self-contained (about 6kb minified). If you are using Node and/or Browserify, this solution might work well for you:
Then you can set an image
src
attribute using jQuery like this: