Find your content:

Search form

You are here

JavaScript to determine Salesforce1 location (native app or mobile browser)

 
Share

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:

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

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?


Attribution to: lwolfe

Possible Suggestion/Solution #1

Try

// Check to see if the device has geolocation 
// detection capabilities with JavaScript
var lat, lon;
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function(position){
        lat = position.coords.latitude;
        lon = position.coords.longitude;

Attribution to: Harshit Pandey
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32238

My Block Status

My Block Content