[英]Setting background image in javascript with base64 data
I'm having trouble setting the background image of a div using a data url. 我在使用数据URL设置div的背景图片时遇到问题。 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+")";
I know this css works: 我知道这CSS的作品:
body {
background: #ffffff url("data:image/jpg;base64,/9j/4...") no-repeat top left;
}
Thus maybe you should: 因此,也许您应该:
从base64字符串中删除换行符(\\ r \\ n),它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.