3

In a VF page I need to call a javascript function that is on javascript file stored in static resource.

Here is the javascript of the VF page :

function callTarif(){
    callStaticResource();
}

But it says me that callStaticResource() doesn't exist...

The static resource is referenced like this in the VF page :

<apex:includeScript value="{!URLFOR($Resource.myFolder, 'myFolder/vv3-3.js')}"/>

UPDATE

The javascript file in the static resource begin with that :

$(document).ready(function(){ 
   callStaticResource();
}

maybe the document.ready is the problem ?

2
  • Tried, works fine for me. Could you be more specific on whats going wrong?
    – Raul
    Jun 5, 2018 at 14:57
  • I updated my question
    – dou
    Jun 5, 2018 at 15:25

1 Answer 1

1

If you look in the documentation for apex:includescript, there's the loadOnReady attribute. Try setting this to true

Specify whether the script resource is loaded immediately, or after the document model is constructed. The default value of "false" loads the script immediately. Set to "true" to cause JavaScript referenced by the component to wait to be loaded until the page is "ready." Scripts loaded this way will be added to the DOM after the onload event is triggered, instead of immediately. This event occurs after the DOM is constructed, but might be before child frames or external resources, such as images, have finished loading.

1
  • I try this but I still get an error on javascript, saying that "callStaticResource is not defined" (on the script of the VF page)
    – dou
    Jun 6, 2018 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .