You need to sign in to do that
Don't have an account?
Prateek Aneja 2
Using Javascript in Static Resource
This is the code I have written in Visualforce to access a Javacsript file:-
<apex:page sidebar="false">
<apex:includeScript value="{!$Resource.Stat1}"/>
</apex:page>
But it is not working.
Javascript Code:
<html>
<body>
<script>
document.getElementById("demo").innerHTML = "Hello Javascript";
</script>
<p id = "demo"></p>
</body>
</html>
<apex:page sidebar="false">
<apex:includeScript value="{!$Resource.Stat1}"/>
</apex:page>
But it is not working.
Javascript Code:
<html>
<body>
<script>
document.getElementById("demo").innerHTML = "Hello Javascript";
</script>
<p id = "demo"></p>
</body>
</html>
Instead of putting HTML elements in your static resource, you are supposed to keep JS code only.
So I would suggest you to stick with following approach. Salesforce automatically adds HTML and Body tags.
<apex:page sidebar="false">
<p id ="demo"></p>
<apex:includeScript value="{!$Resource.Stat1}"/>
</apex:page>
<script> var previousOnload = window.onload; window.onload = function() { if (previousOnload) { previousOnload(); } document.getElementById("demo").innerHTML = "Hello Javascript"; } </script>