• pgriffe
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I need to render my page as a PDF, so I need to move my inline JS to a static resouce.  However, my JS references variables defined on the page.  So, how do I reference dynamic content in a static resource?

 

This page works:

<apex:page standardcontroller="Account" tabStyle="Account">
    <script type="text/javascript">

        var var1 = '{!Account.name}';       
        function testFunction() {document.write(var1);}
        testFunction();         
    </script>
</apex:page>

 

 

Same page rendered as PDF does not work, hence the need for a Static Resource:

<apex:page standardcontroller="Account" tabStyle="Account" renderAs="pdf">
    <script type="text/javascript">    
        var var1 = '{!Account.name}';       
        function testFunction() {document.write(var1);}
        testFunction();         
    </script>
</apex:page>

 

 

Test Static Resource code:

<script type="text/javascript">    
    var var1 = '{!Account.name}';   
    function testFunction()
    {       
        document.write(var1);
    }
    testFunction();         
</script>

 

New page code (does not work):

<apex:page standardcontroller="Account" tabStyle="Account">
    <script type="text/javascript" src="{!$Resource.test}" />
</apex:page>

 


 How do I define the Static Resource script var1 in my VF page?

 

I need to render my page as a PDF, so I need to move my inline JS to a static resouce.  However, my JS references variables defined on the page.  So, how do I reference dynamic content in a static resource?

 

This page works:

<apex:page standardcontroller="Account" tabStyle="Account">
    <script type="text/javascript">

        var var1 = '{!Account.name}';       
        function testFunction() {document.write(var1);}
        testFunction();         
    </script>
</apex:page>

 

 

Same page rendered as PDF does not work, hence the need for a Static Resource:

<apex:page standardcontroller="Account" tabStyle="Account" renderAs="pdf">
    <script type="text/javascript">    
        var var1 = '{!Account.name}';       
        function testFunction() {document.write(var1);}
        testFunction();         
    </script>
</apex:page>

 

 

Test Static Resource code:

<script type="text/javascript">    
    var var1 = '{!Account.name}';   
    function testFunction()
    {       
        document.write(var1);
    }
    testFunction();         
</script>

 

New page code (does not work):

<apex:page standardcontroller="Account" tabStyle="Account">
    <script type="text/javascript" src="{!$Resource.test}" />
</apex:page>

 


 How do I define the Static Resource script var1 in my VF page?