1

we are trying to execute some script after the master page loads.

 <script language="javascript">  
        _spBodyOnLoadFunctionNames.push("FunctionName");   
        function FunctionName()   
        {   
           alert('test');
        }   
    </script>  
</head>

We are not getting the alert. Any thing missing here? Tried to debug in IE, the debugger does not get hit. Why is this?

1
  • 1
    Are you sure the script is actually there in the emitted html?
    – MdMazzotti
    Commented Mar 24, 2014 at 9:19

2 Answers 2

1

You need init.js loaded before _spBodyOnLoadFunctionNames can work, make sure its loaded before running your script. _spBodyOnLoadFunctionNames is an array, that are execute in the ProcessOnLoadFunctionNames function. The ProcessOnLoadFunctionNames is executed in the ProcessDefaultOnLoad function. The ProcessDefaultOnLoad is execute with: ExecuteOrDelayUntilScriptLoaded(ProcessDefaultOnLoad, "core.js");

You could also use ExecuteOrDelayUntilBodyLoaded(FunctionName()); or ExecuteOrDelayUntilScriptLoaded(FunctionName, "core.js");

0

Instead of at the top in the head, put it in a script tag at the bottom of the page.

1
  • should'nt javascript script tags always be in the head?, just asking. Im new to this. Where exactly in the bottom? (right at end of amsterpage?) or before /body?
    – variable
    Commented Mar 24, 2014 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.