Reputation: 634
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 ) {
Upvotes: 0
Views: 119
Reputation: 311
if(navigator.userAgent.indexOf("specific value") != -1) {
// run specialized code
}
Upvotes: 1