Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Get the SharePoint Version Number Using JavaScript

If you’ve always wondered how to get SharePoint Version # by JavaScript,  the SharePoint 2010 Client Object Model introduces the SP namespace for JavaScript (i.e. ECMAScript).  Since it is used in SP.core.js, the namespace should exist if SharePoint is functioning properly.  Although SharePoint 2007 uses a similar JavaScript library core.js, it does not include the SP namespace.  Therefore, it can be assumed that if the namespace exists, the environment is SharePoint 2010.

var _SPVersion = (typeof SP !== ‘undefined’) ? 14 : 12;

In anticipation of future SharePoint versions (assuming they support the Client Object Model in a compatible manner), the currentVersion field of the ClientSchemaVersions class can be used to get the actual version number (rather than assuming the environment is SharePoint 2010).  Although it’s currently unecessary, the above script could be enhanced like:

var _SPVersion = (typeof SP !== ‘undefined’) ? parseInt(SP.ClientSchemaVersions.currentVersion) : 12;

———-

Alternatively, the HTML Document Object Model could be searched for some element specific to either SharePoint 2007 or 2010.  However, this is inherently less reliable and lower performance than accessing a JavaScript object (like the SP namespace).

var _SPVersion = (typeof document.getElementById(‘s4-ribbonrow’) !== ‘undefined’) ? 14 : 12;

Also, the page’s HTTP header could be searched for the custom field MicrosoftSharePointTeamServices but would require the use of either the XMLHttpRequest or ActiveXObject objects.  This method is much more complex, less reliable, and lower performance than accessing the SP namespace and, as SharePoint MVP Mike Smith points out, the retrieved version number is inaccurate anyway.

The post Get the SharePoint Version Number Using JavaScript appeared first on MetroStar Systems Blog.


Viewing latest article 1
Browse Latest Browse All 3

Trending Articles