OnLoad function in Salesforce Visualforce

OnLoad function in Salesforce Visualforce

window.onload or action attribute in apex:page can be used as OnLoad function in Salesforce Visualforce page.

Method 1(Calling Javascript):

<script type = "text/javascript">
    window.onload=function()      
    {        
        alert("Hi");
    };
</script>

Method 2(Calling apex function or method):

Visuaforce page:

<apex:page controller="sample " action="{!onLoad}">

</apex:page>

Controller:

public class sample {
        public sample(){
        }

        public void onLoad(){
            ..................
            ..................
        }
}

Leave a Reply