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 ) {
4
  • Browser sniffing was abandoned 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). Commented Oct 11, 2013 at 1: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? Commented Oct 11, 2013 at 13:51
  • How many markers are "too many"? Commented Oct 14, 2013 at 0:10
  • 2000. I'm loading them from a JSON object. Until IOS7 fixes the memory issue (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.) Commented Oct 14, 2013 at 11:25

1 Answer 1

1
if(navigator.userAgent.indexOf("specific value") != -1) {
  // run specialized code
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.