2
votes

I'm trying to set an image in a static js script but it doesn't work.

var _pointer = document.createElement("DIV");
_pointer.style.backgroundImage = 'url(../images/repeater_1x4.jpg)';

It returns this error:

GET http://localhost:9000/images/repeater_1x4.jpg 404 (Not Found)

I also tried the following since I have static resources mapped from the public folder to the assets/ url path, it doesn't returns any errors, but again it doesn't show the image.

var _pointer = document.createElement("DIV");
_pointer.style.backgroundImage = 'url(@routes.Assets.at("images/repeater_1x4.jpg"))';

In case you're wondering this is in my routes file:

GET     /assets/*file               controllers.Assets.at(path="/public", file)

What's the correct way to do this? I'm using Play! 2.0, my scripts are in public/javascripts and my images are in public/images as you might expect.

1

1 Answers

5
votes

use:

_pointer.style.backgroundImage = 'url(/assets/images/repeater_1x4.jpg)';