Cloning background image with parenthesis in file name

為{幸葍}努か 提交于 2019-12-10 21:42:46

问题


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

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

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);"></DIV>

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.


回答1:


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




回答2:


you are misssing a quote character: "

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

should be

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

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




回答3:


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




回答4:


&#40; for Left parenthesis '('

&#41; for Right parenthesis ')'

Maybe that'll fix the problem?



来源:https://stackoverflow.com/questions/1162270/cloning-background-image-with-parenthesis-in-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!