2

What I'm trying to do is build a dual purpose JavaScript that might run inside or outside of SharePoint, so I need something like this:

if(SharePoint CSOM Exists)
{
//Do a bunch of stuff involving the SharePoint CSOM as well
}
else
{
//We can run outside of SharePoint as well
}

Is there a standard for doing this? My hunch says it's just if(SP){} but wanted to double check.

1 Answer 1

2

I think the style of script you're writing is probably fairly unique in the wild (how do you handle authentication if you're in the non-SP case and you use something like a REST request, for instance?) so you may not find a genuine 'standard' for doing this -- but checking for the SP object being initialized would be sufficient in most cases.

If you wanted to be a bit more specific, I would actually check for SP and SP.ClientContext since practically everything in the Javascript Client Object Model relies on the ClientContext.

1
  • The JavaScript in question does not really need authentication. Most of the SharePoint stuff is adapting styling and using SharePoint modals.
    – tekiegreg
    Commented Sep 3, 2014 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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