This is in reference to this answer: Embed png image in html file using Jinja2
Is it possible to embed the base64 encoding of my image once in the Html, but use it in many places? I can use jQuery if needed.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simply put your base64 image in an IMG tag, say with an id=”logo”, then wherever you want to use it just have an IMG tag with an empty “src” attribute and a class=”logo”. Then use jQuery to set the “src” attribute for those IMGs to the master. e.g.
jQuery:
HTML:
I’m glad you asked this question as it’s something I wanted to do a couple of weeks ago in a lightbox clone (slimbox2). I wanted to embed the image in the javascript, rather than load it from a file, since the image is specific to the javascript (nice “next”, “prev”, “play”, “pause” buttons) and I did not want the user to have to store them in a specific location.
BEWARE, this type of data is fine for IE8 and above but apparently not Internet Explorer 7 and below. See:
Regards
Neil