admin管理员组

文章数量:1208155

I'm loading a bunch of files as background-image using jQuery and I have this image that will simply not load. The browser does not throw any error.

I know the problem is that the file name contain parentheses (), but I've tried all sorts of things and nothing works. This is not a duplicate from this question as the solution there does not work.

This is the URL of the file

(1).jpg

I've tried different things in Javascript with no luck.

unescape(str);

encodeURI(str)

Even directly replacing the characters

str.replace("(", "%28");
str.replace(")", "%29");

Even by pure desperation

str.replace("(", "(");
str.replace(")", ")");

Help me StackOverflow, you are my only hope.

Please do not suggest to change the file name. I do not have access to that file.

I'm loading a bunch of files as background-image using jQuery and I have this image that will simply not load. The browser does not throw any error.

I know the problem is that the file name contain parentheses (), but I've tried all sorts of things and nothing works. This is not a duplicate from this question as the solution there does not work.

This is the URL of the file

http://oceanhotelsimages.com/uploads/200x150_Privilege_Lounge_OBS_05_(1).jpg

I've tried different things in Javascript with no luck.

unescape(str);

encodeURI(str)

Even directly replacing the characters

str.replace("(", "%28");
str.replace(")", "%29");

Even by pure desperation

str.replace("(", "(");
str.replace(")", ")");

Help me StackOverflow, you are my only hope.

Please do not suggest to change the file name. I do not have access to that file.

Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Apr 10, 2015 at 2:26 PierPier 10.8k17 gold badges72 silver badges118 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 26

The solution was easier than I thought. I was missing the quotes when declaring the url of the CSS property.

$(this).css({
    "background-image": "url('" + someString + "')"
});

本文标签: javascriptUsing image URL with parentheses as background with jQueryStack Overflow