You need to sign in to do that
Don't have an account?

How to reference Static Resources from JavaScript?
Hi,
I have uploaded some JS script and an image to Static Resources (zipped), then included it using the includescript tag in my page, and now I want to make references to some image in there from within JavaScript. How can I do that? i.e. what path do I use for the image?
The VF guide states that includescript is translated to the following HTML:
<script type='text/javascript' src='/resource/1233160164000/example_js'>
But what does that long number mean? I was thinking that maybe I could use the rendered HTML to reference the image thru JS.
Any ideas please? Thanks!
Here's an example from one of my orgs:
<img src="{!URLFOR($Resource.MyResources,'images/section_icons/sect-details.png')}"/
Thanks, though, I was looking for something slightly different :) I wanted to use the path for some file in Static Resources, say an image, in JavaScript (not in VF). So something like:
var path = path_to_image;
I may be able to use actionFunction to do this..
In that case, wouldn't you just use the URLFOR, e.g.
var path="{!URLFOR($Resource.MyResources,'images/section_icons/sect-details.png')}";
Hi !
I've exactly the same problem and would like to know if there is any workaround ... I've seen some post about it and the solution using VF pages is given several times, but it doesn't answer what is asked.
I tried using a variable as bob_buzzard said, but isn't working either (inside onclick button javascript code).
Please, any help is appreciated
Thanks !!
This light might be able to help out
http://jevonearth.blogspot.com/2011/08/using-static-resources-with-salesforce.html
Please refer
http://www.salesforce.com/us/developer/docs/pages/Content/pages_resources.htm
You can use JSENCODE to get the static resource path in javascript. For example if you want to retrieve the path of the image you stored in static resource you can use the below:
var img_path = '{!JSENCODE($Resource.testImage)}'