7

While trying to overcome the problem with <apex:outputLink target="_blank"> not working under Lightning Experience, I found this atricle; they propose checking the {!$User.UIThemeDisplayed} return value to understand, if the VF page is currently rendered under Classic UI or LX (Lightning Experience) UI.

I applied <apex:outputLink target="{!IF($User.UIThemeDisplayed == 'Theme3', '_blank', '_self')}" ...> as a solution, so that the link either opens in a new tab under Classic UI, or "replaces" currently viewed page under the LX UI.

This solution worked correctly just yesterday, but today the check fails: for some odd reason, $User.UIThemeDisplayed now returns "Theme3" even when I access the page from LX UI. I have created a testing VF page to check this behavior, (also checking the presence of some JS objects available only under Salesforce1):

<script type="text/javascript">
(function(myContext){
    myContext.ForceUI = myContext['ForceUI'] || {};

    myContext.ForceUI.UserUIThemeDisplayed = '{!$User.UIThemeDisplayed}';
    myContext.ForceUI.UserUITheme = '{!$User.UITheme}';
    myContext.ForceUI.isSalesforce1 = (typeof sforce != 'undefined') && sforce && !!sforce.one;

    // Output results into the <div> element on this page
    var targetEl = document.getElementById('debugOutput');
    if (targetEl && myContext.ForceUI) {
        targetEl.innerHTML = '<pre>' + JSON.stringify(myContext.ForceUI, null, '    ') + '</pre>';
    }
})(this);
</script>

DebugOutput under Classic UI:

{
    "UserUIThemeDisplayed": "Theme3",
    "UserUITheme": "Theme3",
    "isSalesforce1": false
}

DebugOutput under Lignting Experience UI:

{
    "UserUIThemeDisplayed": "Theme3",
    "UserUITheme": "Theme3",
    "isSalesforce1": true
}

As you can see, only checking the sforce object's availability has worked correctly...

Looks like a bug?.. Has anyone faced with the same problem?


Additional info: I have just found this is a browser-specific issue. This is only reproduced under Mozilla Firefox browser.

Your Answer

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

Browse other questions tagged or ask your own question.