Home > Uncategorized > Adding JavaScript function to SharePoint application pages

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>

Advertisement
Categories: Uncategorized
  1. Ryan
    August 26, 2010 at 8:34 pm | #1

    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

  2. Ryan
    August 26, 2010 at 8:37 pm | #2

    poor formatting on my part sorry. i cannot write script type=”text/javascript” tags(including the >< again)

  3. Ryan
    August 26, 2010 at 9:17 pm | #3

    nevermind, figured it out. A javascript block needs to be placed insside asp:content blocks, it cannot sit outside. Thanks though

    • September 2, 2010 at 7:49 pm | #4

      Hey Ryan, glad you got this one sorted and thanks for sharing your solution :)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.