I have a visualforce page on which I want to conditionally render two output panels, one is rendered if the current user is switched to lightning experience and the other is rendered if the user is switched to salesforce classic experience.
The page can be opened from a link contained in a chatter post and in an email sent to the user from apex code.
The solution that I have currently implemented is to check the value returned by "document.referrer" on page load. If the value contains "lightning.force.com" I display the first output panel (let's say Lightning Output Panel) and if not then I display the second output panel (let's say Classic Output Panel), but this doesn't work in case the user tries to open the page from the link in the email because here the document.referrer always returns a blank string and always the second output panel (Classic Output Panel) is displayed.
I have also tried
var isSF1 = typeof sforce !== 'undefined';
but in my case "sforce" is always null because I am opening the page from a url I built in my apex controller. If I try this on a page opened from a record detail page button/link (or from anywhere within the org for the matter) then it works just fine.