3

I have created a vf page and added some javascript into that vf page which is using controller variable :

<apex:page controller="webstore">
<script>
    var username = '{!username}'
</script>
</apex:page>

It was working fine till the script was on vf page. Now, I have removed script from the vf page and created a static resource and have placed script into that. I have added that static resource into my page but now that script is not working. The script has been unable to identify that controller variable. It seems that controller variable doesn't work in this way. Is this a problem or I am missing something ?

1 Answer 1

6

Only Visualforce page (and component) files go through the binding to the controller process; static resource files do not.

If the amount of JavaScript is small then leaving it in the page is the simplest approach. If you have more JavaScript, you can create a JavaScript object in the page that has the controller values assigned, and reference that in the JavaScript that is in the static resource.

2
  • 1
    I have created those required variables into my vf page and have included script after that and it's resolved the issue. Just wanted to confirm if this is possible or not. Thanks!!!
    – S.Sharma
    Commented Jun 5, 2014 at 9:00
  • @S.Sharma then you should mark this answer as "Accepted" Commented Aug 25, 2015 at 19:51

You must log in to answer this question.

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