user4402918
user4402918

Reputation: 63

Setting background image in javascript with base64 data

I'm having trouble setting the background image of a div using a data url. Here's my code, which doesn't throw an error but also doesn't work:

profilePhotoData= shout.get("authorProfPic");

src = 'data:image/png;base64, ' + profilePhotoData.base64

outerDiv.style.backgroundImage="url("+src+")";

Upvotes: 0

Views: 5140

Answers (3)

romainsalles
romainsalles

Reputation: 2143

I know this css works:

body {
  background: #ffffff url("data:image/jpg;base64,/9j/4...") no-repeat top left;
}

Thus maybe you should:

  • try the background property.
  • add the " between your url brackets

Upvotes: 2

Kees
Kees

Reputation: 1418

Remove the line breaks (\r\n) from the base64 string and it should work.

Upvotes: 0

User
User

Reputation: 276

Not sure you can do that, you can try to do it with classes instead.

Have a look Here

Upvotes: 1

Related Questions