8

Our add-in needs to execute different JavaScript code on SharePoint on premises and on SharePoint Online. There is a slight difference, but it is critical for our add-in. The add-in is a pure JavaScript application, it does not have any server-side code.

How do I detect SharePoint 2013/2016 On Premises vs SharePoint Online in JavaScript?

  • 2
    well, sharepoint online is going to have a host name of tenant.sharepoint.com, so that will get you on prem vs cloud – Eric Alexander Jul 26 '16 at 17:50
  • You can setup your own domain as far as I remember. – IT Hit WebDAV Jul 26 '16 at 19:29
  • That is only for the public facing web site, which is going away. – Eric Alexander Jul 26 '16 at 20:41
  • What if some third-party hosting provider (not MS) will be hosting SharePoint Online version? Not sure if they use the same version as deployed to *.sharepoint.com or "real" SPS 2013/2016. – IT Hit WebDAV Jul 27 '16 at 16:47
  • That would be the same as a 2103/2106 on prem installation for all intents and purposes – Eric Alexander Jul 27 '16 at 16:53
6

An easy check for SharePoint Online or on premises would be to look at the host name. In the case of SharePoint Online, it will always be in the form of tenant.sharepoint.com. A local installation, third party hosted, or something running in Azure, it will be for all intents and purposes the same thing, an on premises installation.

This then leads to how can you determine 2013 vs 2016. In pure javascript it would look something like:

var context = SP.ClientContext.get_current();
context.executeQueryAsync(
  function(){
    serverVersion = clientContext.get_serverVersion();
    //do something else
  }, 
  function(){
    console(args.get_message());
  }
);

This comes with some risk as I don't really know what you then want to do. For example, running this against my Online tenant says 16.0.5507.1207. This would infer that I'm on 2016, but my site collections are still in 2013 mode, so it may or may not suit your need.

  • Slight correction, but this is exactly what I was looking for thanks! var context = SP.ClientContext.get_current(); context.executeQueryAsync( function(){ serverVersion = context.get_serverVersion(); console.log(serverVersion); }, function(){ console(args.get_message()); } ); – Xopher Jan 22 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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