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
jhoustonjhouston 

Javascript + Static Resources issue

I have a zip file with my static resources (images,css,js) and everything is linking correctly except for one thing.

 

I'm using javascript that to get the image ID and swap out an image in the navigation. This is an animated gif. 

 

Here's the java:

function gifload()
{
parent.document.getElementById('sync').src='images/sync_anim.gif';return false;
}

 

 

The site is set up with navigation outside of an iframe, so the javascript gets called whenever a new page is loaded within the iframe (there's an additional function that does this on page load). 

 

Now this code all works fine in HTML, and it even works in salesforce.com if I point the image source to an external site. But I can't get it to load the image from within the static resources. 

 

Can anyone shine some light on how to resolve this issue?

 

Thanks much

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

I think that there's something crazy going down. I suspect it's a combination of not being able to set the cache control on the image to 'public' and using the site within an iFrame.

 

As a workaround(not elegant in the least) try uploading your image as a Document(click on the tab within salesforce that has a right pointing arrow, and click documents, and upload yours) . Your image will be available to your javascript by using the following URL

 

/servlet/servlet.FileDownload?file=

 

and concatenting your uploaded document id onto the end of that.

 

Not sure if that'll work, I've used it in a few places but the iFrame might introduce some trickiness.

 

Cheers,

Wes

All Answers

wesnoltewesnolte

Hey

 

If you edit your static resource you'll have an option 'Cache Control'. Try setting this to public.

 

Cheers,

Wes

jhoustonjhouston

Thanks, but I don't see this option. When I click edit on Static resource it appears I can only do three things. Change the name, change the description, and (re)upload the file. I'm in App > Develop > Static Resources, is there another place the Static resources can be edited? Or the cache control?

Message Edited by jhouston on 06-15-2009 01:29 PM
ShamSham

I guess the path of the image is not being set correctly.

Try setting the path to 

 

parent.document.getElementById('sync').src={!URLFOR($Resource.ResName,'/images/sync_anim.gif')};

 

jhoustonjhouston

Thanks, I have tried this... but it still doesn't load the image...

 

I'm new to the salesforce syntax but I don't think the !URLFOR can be used in static resources. Since the images directory is in the same zip it should work just like CSS & Images. However, when I have just 'images/sync_anim.gif' it replaces the initial img with nothing. 

 

Hmm... I thought maybe the gif was conflicting with salesforce, but any image I try to reference this way gives me the same result: nothing. 

wesnoltewesnolte

Very strange, I've just done the same and I see the option there. For me it's below the 'Browse' button. You have Salesforce Site's enabled right?

 

 

Wes

jhoustonjhouston
I'm not sure... what does that mean? How do you enable/disable this function?
wesnoltewesnolte

Okay, I assumed you'd set it up because you've posted in the 'Sites' board. Sites is part of the salesforce product (or can be if you enable it). It's almost like having a site hosted by salesforce that is publicly available and doesn't require a logon. I *think* these discussion boards are made using sites.

 

I've reread your original post and it tell me if I'm correct:

 

You're have the salesforce http://login.salesforce.com link within an iframe of another page?

 

Wes

jhoustonjhouston

Eventually, I believe this will be a salesforce 'site', but as is it's in development and is not ready to be publically listed. Is this the wrong forum to be posting in? I admit I'm new to the platform and forums.

 

I'm testing pages through https://na5.salesforce.com/apex/nameofpage

 

Just as an example this how it's set up:

 

https://na5.salesforce.com/apex/main — this is my main page, it contains navigation and an iframe

 

https://na5.salesforce.com/apex/content — this would be the initial content loaded into the iframe, links from within stay in the iframe. The navigation items are also loaded into the iframe. 

 

So the content and subsequent pages load javascript that swaps out one of the icons so that it animates and creates/imitates a 'loading' sort of precense.

 

The javascript is functioning correctly but only if I use an external source for the image. I cannot seem to use static resource within the zip or otherwise.  

 

 

wesnoltewesnolte

I think that there's something crazy going down. I suspect it's a combination of not being able to set the cache control on the image to 'public' and using the site within an iFrame.

 

As a workaround(not elegant in the least) try uploading your image as a Document(click on the tab within salesforce that has a right pointing arrow, and click documents, and upload yours) . Your image will be available to your javascript by using the following URL

 

/servlet/servlet.FileDownload?file=

 

and concatenting your uploaded document id onto the end of that.

 

Not sure if that'll work, I've used it in a few places but the iFrame might introduce some trickiness.

 

Cheers,

Wes

This was selected as the best answer
jhoustonjhouston
Cool, thanks, that helps. It does work with the document link. Out of curiousity do you know if this link will change— especially when the site is public? Thanks for your help Wes!
wesnoltewesnolte

Glad to be able to help :)

 

The link is the same for the public site, I use it in both cases. The link itself forms part of the Salesforce 'How to display a document as an image'(or something to that effect) so I'm sure it won't change soon*holds thumbs*