Recently I faced this scenario where I needed to determine based on whether I am on-premise or online, I needed to write my logic accordingly. We have our popular Sharepoint Utility which is used by a lot of customers and we had to perform special operations depending on whether it is installed on-line or on-premise.
Xrm.Utility.getGlobalContext() gets the global context and has method to know whether your model driven app is hosted on-premise or online.
To get the value first the get the global context
var isOnPremises = globalContext.isOnPremises();
Simple yet effective built-in method available in global context.
Hope it helps!
(Business Solutions MVP)
For training and consulting, write to us at email@example.com