2

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 Answer 1

5

use:

_pointer.style.backgroundImage = 'url(/assets/images/repeater_1x4.jpg)';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.