Adding JavaScript function to SharePoint application pages
Hi there, just a quick and simple posting today. At some point you may need to call some custom java script when your page loads in SharePoint. To have your custom function called during the onLoad event simply add the _spBodyOnLoadFunctionNames.push method. to your script block
Sample script block added to your application page in SharePoint…
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push(
"someFunction");
function someFunction() {
alert(
"Hello world!)";
}
</script>
del.icio.us Tags: SharePoint spBodyOnLoadFunctionNames
Advertisement
Categories: Uncategorized


I have been trying to add javascript to a custom application page for some time. I am unable to add a tag to my application page, and the _spBodyOnLoadFunctionNames method is not recognized. If I try to write a javascript block on the page i get an error along the lines of ‘content cannot be included outside or tags. Can you elaborate some more on how you accomplished this? My application page is essentially the same as an example included in the WSS 3 SDK
poor formatting on my part sorry. i cannot write script type=”text/javascript” tags(including the >< again)
nevermind, figured it out. A javascript block needs to be placed insside asp:content blocks, it cannot sit outside. Thanks though
Hey Ryan, glad you got this one sorted and thanks for sharing your solution