Michbeckable
Michbeckable

Reputation: 1881

URL escape for jQuery

I have the following url:

http://s7w2p3.scene7.com/is/agm/creativprint/a4?&page=3&wid=354&fmt=jpg,rgb&setAttr.img_page3={source=@Embed%28%27/ugc/8423326.tif%27%29}. 

I want to set this as the url of background-image of a div via jQuery('#divID').css or document.getElementByID('divID').style.backgroundImage. It does not work, as I suppose I have to escape some charaters in it. The Javascript global function escape() doesnt do the trick either.

I have set it manually as background-image in my .css file and it works. Any suggestions? I have tried it with other URLs of the format http://s7w2p3.scene7.com/is/agm/creativprint/a4?&page=3&wid=354&fmt=jpg,rgb. That works. So the problem must be in the remaining part: &setAttr.

Upvotes: 0

Views: 577

Answers (2)

ThiefMaster
ThiefMaster

Reputation: 318508

You might have just forgotten the url() around the CSS property:

$('#id').css('backgroundImage', 'url("http://s7w2p3.scene7.com/is/agm/creativprint/a4?&page=1&wid=354&fmt=jpg,rgb&setAttr.img_page1={source=@Embed%28%27/ugc/4575272.tif%27%29}")');

It works fine for me that way: http://jsfiddle.net/mPyTJ/1/

Upvotes: 1

jfrej
jfrej

Reputation: 4648

I can't see what your problem is. Everything seems to be working just fine. See this jsFiddle.

$(document).ready(function(){
    $('#div1').css('backgroundImage','url(http://s7w2p3.scene7.com/is/agm/creativprint/a4?&page=1&wid=354&fmt=jpg,rgb&setAttr.img_page1={source=@Embed%28%27/ugc/4575272.tif%27%29})');
});

If you could reproduce your error using jsFiddle that would help a lot.

Upvotes: 0

Related Questions