views:

316

answers:

4

I have a background image with a parenthesis in the filename:

<DIV style="BACKGROUND: url('http://site.com/image(8).png');"&gt;&lt;/DIV&gt;

This is fine normally, and there is no confusion because there are quotes around the file name.

Looking in IE's developer tools however, I see that the browser stripped the quotes for some reason.

<DIV style="BACKGROUND: url(http://site.com/image(8).png);"&gt;&lt;/DIV&gt;

Still, it works, so not a big deal. The problem comes when I try to use jquery's clone function.

Apparently, the output after clone() does not recognize the above image url as valid in IE8 and strips it out (other browsers, including IE7, are fine). And so I end up with this:

<DIV></DIV>

Anyone know how to fix this? That is, clone a background image with parenthesis in the url in IE8.

Thanks.

Also, as an addendum I have to use inline styling in for the relevant elements, so please don't recommend using a separate stylesheet.

Ad2: On escaping, After browser rendering the escaped entities becomes unescaped. Cloning again happens after page load, and the selected object to clone has unescaped characters in them.

A: 

Escaping the parentesis would work I guess. TBH, it would be the way I would use it on a URL.

wtaniguchi
After browser rendering the escaped entities becomes unescaped. Cloning again happens after page load, and the selected object to clone has unescaped characters in them.
Jourkey
+1  A: 

you are misssing a quote character: "

<DIV style="BACKGROUND: url('http://site.com/image(8).png');&gt;&lt;/DIV&gt;

should be

<DIV style="BACKGROUND: url('http://site.com/image(8).png');"&gt;&lt;/DIV&gt;

you can see here that even the stackoverflow code formatter formats the code different

Alright, sorry fixed.
Jourkey
+1: That's the mistake I believe. Since there shouldn't be any problem with parenthesis in the name if you add quotes.
kuroir
Thanks, but it's not the answer.
Jourkey
A: 

&#40; for Left parenthesis '('

&#41; for Right parenthesis ')'

Maybe that'll fix the problem?

Vian Esterhuizen
I edited the top post with an explanation about escaping.
Jourkey
+2  A: 

Don't escape the parentheses with HTML entities (the browser is correct to treat entities in attributes as their literal character equivalent), escape them with URL entities:

( = %28
) = %29

eyelidlessness
Thanks. Yay that did it.
Jourkey