I've found that I need some different behaviors based on whether the user is visiting my VisualForce page via the Salesforce1 native app (iOS or Android) or is using a mobile browser on the /one/one.app URL. I've seen answers for testing sforce.one to determine if the user is on Salesforce1, but this doesn't help for native vs. mobile web.

This post mentioned testing for SalesforceTouchContainer in the user agent string. I'm not actually seeing that work, but the following JavaScript does seem to work properly for me on both Android and iOS:

var isSalesforceNative = (window.navigator.userAgent.toLowerCase().indexOf('salesforce1') != -1);

It works, but it feels hacky to me. Does anyone have a better suggestion on how to do this, or is user agent sniffing really the only way?

  • There is no supported way, so anything you do is a hack. I think what you've done here is okay.
    – Kris Gray
    Commented Jul 17, 2014 at 23:19
  • wouldn't testing window.top.location.href for '/one/one.app' work? Or is that URL the same for both native and mobile browser? Commented Oct 26, 2015 at 9:13

1 Answer 1



// Check to see if the device has geolocation 
// detection capabilities with JavaScript
var lat, lon;
if (navigator.geolocation) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;
  • 1
    Mobile browser and native app might both have geolocation enabled... Commented Oct 26, 2015 at 9:10

You must log in to answer this question.

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