Determining the Salesforce Style That Users See in JavaScript

If you use a lot of JavaScript in your pages and apps, identifying the Salesforce theme that a user sees in JavaScript code is important. Identifying the current user experience context allows you to correctly manage navigation in your JavaScript code.

The UITheme.getUITheme() JavaScript function returns a string containing one of the following values to identify the current user interface theme.

The string values returned are the same values returned by the Visualforce $User.UITheme and $User.UIThemeDisplayed global variables.

The following markup checks if the current user experience context is the Lightning Experience theme.

function isLightningDesktop() {
  return UITheme.getUITheme === "Theme4d";
}