I have a Lightning Component which loads in both Mobile(SF1) and Desktop, is there a way to detect the client(who is requesting Mobile or Desktop) based on the parameter value I need to render some attributes inside the component.

How could I go about this?

Thanks

  • you can use javascript for this. – Tushar Sharma Dec 2 '15 at 3:40
up vote 4 down vote accepted

The $Browser global value provider returns information about the hardware and operating system of the browser accessing the application.

Returns a FormFactor enum value based on the type of hardware the browser is running on.

  1. DESKTOP for a desktop client
  2. PHONE for a phone including a mobile phone with a browser and a smartphone
  3. TABLET for a tablet client (for which isTablet returns true)

Ctrl

({
    checkBrowser: function(component) {
        var device = $A.get("$Browser.formFactor");
        alert("You are using a " + device);
    }
})

Component

<aura:component>
        {!$Browser.isTablet}
        {!$Browser.isPhone}
        {!$Browser.isAndroid}
        {!$Browser.formFactor}
    </aura:component>

By using this way you can determine

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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