2

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?

  • There is no supported way, so anything you do is a hack. I think what you've done here is okay. – Kris Gray Jul 17 '14 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? – Willem Mulder Oct 26 '15 at 9:13
-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;
  • 1
    Mobile browser and native app might both have geolocation enabled... – Willem Mulder Oct 26 '15 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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