function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JWikkJWikk 

Visualforce page to run javascript onload?

is it possible to have javascript run upon opening a visual page? I know I can get the apex controller constructor to run, but I want javascript to access the browser url.

 

The following only works in development mode:

<script type="text/javascript">
    
    var detailURL= parent.document.referrer;
    detailURL = detailURL.substring(detailURL.lastIndexOf('/')+1);

    function init() {
        
        if ((detailURL > "" ) && (detailURL.length == 15)) {
            alert('pushing '+detailURL);
            nowPushURL(detailURL);
            
        }
    }
    parent.onload = init; //window.onload;
    </script>

 

Best Answer chosen by Admin (Salesforce Developers) 
asadim2asadim2

Use this instead:

 

 

<BODY onLoad="init()"/>

 

 

All Answers

asadim2asadim2

Use this instead:

 

 

<BODY onLoad="init()"/>

 

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

Try out sample code given below :

 

            window.onload = new function() { checkCondition(); };

            function checkCondition()

            {

              // your logic here

             }

 

Hope this helps.