Quantcast
Channel: MetroStar Systems Blog » javascript
Viewing all articles
Browse latest Browse all 9

Helpful JavaScript Functions for SharePoint

$
0
0

There is no mistaking it, when it comes to SharePoint 2010 and on, JavaScript plays a huge role. A lot of the JavaScript you generally don’t see however, and if you don’t know where to look, you might not know how to take advantage of it in your own coding. So I thought I would put together a list of utility functions that I have found/created along the way.

First I will go over some functions which are provided out of the box, and can be found within the JavaScript Object Model, SP.Utilities Namespace.

  • SP.Utilities.HttpUtility.appendSourceAndNavigateTo(url)
    This function simply navigates the current window to the URL provided and adds an encoded Source.
  • SP.Utilities.HttpUtility.htmlEncode(str)
    This function takes a string that you pass in and HTML encodes it by replacing ampersand (&), double-quotation (“”), single-quotation (”), less-than (<), and greater-than (>) characters with the appropriate characters.
  • SP.Utilities.HttpUtility.urlKeyValueEncode(keyOrValueToEncode)
    This function does a really good job of encoding Query String parameters. For instance if you have a period (.), this will encode it properly, as opposed to the out of the box encodeURIComponent JavaScript function.
  • SP.Utilities.Utility.getLayoutsPageUrl(pageName)
    This function returns a server relative URL for a page that is within the Layouts directory on the Web Front End server. Honestly, this one is my favorite, and I use it all the time.

Additionally, below are some functions that I have created or modified for my own purposes. These functions can be found within my Core.js file, here.

  • getCurrentWebRelativeUrl()
    This function gets a relative URL for the current web. If the current web is the root of the web application, a “/” is returned.
  • resizeDialog()
    This function causes a modal dialog to resize to fit the content. This can be useful in situations when you have forms with fields that change dynamically.
  • getQueryStringValue(key)
    This function returns a Query String value based on the key provided. If no key is found, returns undefined.

Hopefully these are helpful.

References:

The post Helpful JavaScript Functions for SharePoint appeared first on MetroStar Systems Blog.


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images