function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How can I refer static resource image in static resource javascript file?

I have a static resource javascript file with code -

var strTbl1='';
strTbl1+='<td align="center" width="15" height="20"> <img src="cancel.png" border="0"/> </td>';

I have an image, it is not in zip file, with name "cancel" in static resource.
How can replace  "<img src="cancel.png" border="0"/>" with static resource image?


Try the following - not sure if you can just reference the resource or if you need to append /cancel.png to end (typically working with zip files).



<img src="{!$Resource.cancel}" border="0"/>


<img src="{!$Resource.cancel}/cancel.png" border="0"/>





I think the question is more about referencing the image file directly in the javascript file, and not referring to it in markup.


So in that case you need to zip your files together.  Then you can reference your javascript file on your page using URLFOR and $Resource, and your javascript file can reference your image via the path to it in your zip.