I have a problem with a plugin I am using, where I need to assign a background through jquery.
I get the following url back from the database:
http://www.website.com/upload/projects/25/opbouw_(10)_(800x600).jpg
And it is not displaying this image because of the brackets in the url. I can not change this url because a client hast uploaded it. Before you point out the security issues about this: I did not wrote it and I can not change it either. So I'll have to deal with this, unfortunately.
I have found a similar question about spaces in a javascript url, but you can use encodeURIComponent and encodeURI to solve that problem, however, the () are unescaped characters and will not be formatted properly.
My question is, what am I supposed to do to make sure the image shows properly? Some kind of Regex? (I suck at Regex btw).
Thanks! :-)
Edit:
some javascript code...
iw.css({'background-image':'url('+ent.data("src")+')','backgroundPosition':'50% 49%', 'backgroundSize':'cover', 'background-repeat':'no-repeat'});
ent.data("src") is the url I get back
The "correct" way to define a background image is like so:
url("/path/to/image.jpg")
Note the use of quotes. People always seem to forget the quotes... They are optional in most cases, but as seen here they are required for proper parsing. Add them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With