How to refresh Apex variable inside Javascript?

Workaround:

Move the Javascript inside apex:outputPanel and rerender the apex:outputPanel to refresh Apex variable inside Javascript.

Don't keep the Javascript snippet in the beginning of the page, move it to the last before </apex:page> tag.

Sample Code:

<apex:page> 

<apex:pageBlock>
   /*...........................
    Your VF page code here


    ..........................*/
</apex:pageBlock>

<apex:outputPanel id="jspanel">
    <script type="text/javascript">
        function cancl()
        {
            Check = "{!flag}";
            if(Check == "true")
            {
                var pid='{!$CurrentPage.parameters.pid}';
                top.location=window.location.protocol + '//' + window.location.host+'/'+pid;
            }   
        }
    </script> 
</apex:outputPanel>

</apex:page>

here flag is an Apex variable.

No comments:

Post a Comment