You need to sign in to do that
Don't have an account?
Raj R.
How to include javascript in visualforce?
Hi,
I am creating a visualforce page where I am trying to include two javascript files, but they are not running when the VF page loads. What is the correct way to include javascript in VF?
I have tried (with no luck):
I am creating a visualforce page where I am trying to include two javascript files, but they are not running when the VF page loads. What is the correct way to include javascript in VF?
I have tried (with no luck):
- <script src="{!$Resource.jquery}"></script>
- <apex:includeScript value="{!URLFOR($Resource.jquery, 'jquery.min.js')}"/>
I tried it on my system and I think you way to refering javascript is correct . Please take care of name of static resource like you created a new static resource named 'jquery' having file 'jquery.min.js' . So you have to use static resource name like <script src="{!$Resource.jquery}"></script> . Or by include script like <apex:includeScript value="{!$Resource.jquery}"/> . If it is correct then jquery is included , It might override by any other jquery .
So please let me know if it helps or need further elebroation .
Thank you
All Answers
I tried it on my system and I think you way to refering javascript is correct . Please take care of name of static resource like you created a new static resource named 'jquery' having file 'jquery.min.js' . So you have to use static resource name like <script src="{!$Resource.jquery}"></script> . Or by include script like <apex:includeScript value="{!$Resource.jquery}"/> . If it is correct then jquery is included , It might override by any other jquery .
So please let me know if it helps or need further elebroation .
Thank you
Please use the below Syntax :
<apex:includeScript value="{!$Resource.MyJavascriptFile}"/>
//MyJavascriptFile is name of your static resource in which JS file is stored.
Abhishek
try with this
<script src ="
{!$Resource.MyJavascriptFile}
" type="text/javascript" />
use urlFor if you have uploaded a zip file .
Hope this helps.
this might help