6

Are there any way to detect that user opens lightning component within Salesforce1 or within separate app?

2 Answers 2

5

Some events are handled specifically within Salesforce1, so you can use that to check context. See this link for a list of Salesforce1 events.

This example displays a toast message in Salesforce1 but not in a standalone/separate app.

var toast = $A.get("e.force:showToast");
if (toast){
    toast.setParams({
        "title": "Success!",
        "message": " Your contacts have been loaded successfully."
    });
    toast.fire();
} else {
        console.log("not in Salesforce1");
    }

Update - April 9, 2015 I was advised by an S1 developer that you can also use $A.getContext().getApp() to get context.

if (context=="one:one") {
            //you're running Salesforce1
        }
        else {
            //you're running a standalone app
        }

See the JavaScript API docs (https://[your-salesforce-instance]/auradocs/reference.app#reference?topic=api:Aura) for more details.

2
  • Looks like they updated this to context=="native:bridge" worry that this is not best practice although does appear to work on ios / android.. Nov 10, 2015 at 7:24
  • 1
    In 2017 I don't see getContext() or getApp() methods in $A documentation... any updated solution?
    – Wookie88
    Sep 5, 2017 at 13:01
1

I Know its old question but might be help full for other users as of new release, there is support by salesforce to find the context

 const device = $A.get("$Browser.formFactor"); // DESKTOP,PHONE

Returns Desktop or Phone

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_browser_value_provider.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .