0

I already know how to identify the user agent of a browser. Now, within my javascript, there is a certain section of it that I do not want to use if the user agent is a specific value. Is there a way to turn on and turn off this specific section of javascript based on the user agent? I can use javascript or jQuery to accomplish it.

The javascript in question is for mapping markers in Google Maps API. Here's the relevant piece:

    function initialize() {
          var rendererOptions = {
          draggable: true,
          panel:document.getElementById('directions_panel')
         };

          directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
          var chicago = new google.maps.LatLng(41.850033, -87.6500523);
              var mapOptions = {
              zoom: 6,
              center: chicago,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            }
          map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    // I WANT TO TURN OFF THE LINES BELOW AND A FEW OTHERS THAT FOLLOW

        $.getJSON( "/mapall.js", {}, function( data ) {
        $.each( data, function( i, item ) {
KDP
  • 634
  • 1
  • 11
  • 31
  • [Browser sniffing was abandoned](http://jibbering.com/faq/notes/detect-browser/) a very long time ago in favour of feature detection. The user agent string is not reliable for detecting the browser or browser functionality and so is a bad strategy if you are attempting to avoid browser quirks (unless your goal is to write scripts that need constant maintenance). – RobG Oct 11 '13 at 01:20
  • RobG, thanks for the info. My main problem is that IOS7's memory issues are crashing the mapping application because I'm loading too many markers. How would I use feature detection for this purpose? – KDP Oct 11 '13 at 13:51
  • How many markers are "too many"? – RobG Oct 14 '13 at 00:10
  • 2000. I'm loading them from a JSON object. Until IOS7 fixes the memory issue (http://stackoverflow.com/questions/18759401/google-map-crashes-in-ios7), I'm looking for a way to turn off the marker load for IOS7 only (or, barring that, all mobile devices.) – KDP Oct 14 '13 at 11:25

1 Answers1

1
if(navigator.userAgent.indexOf("specific value") != -1) {
  // run specialized code
}
keslert
  • 311
  • 1
  • 8