Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

test for ie in jquery

I am using a custom icon for a Google map marker. Problem is that ie<9 does not support my custom marker so I would like to conditionally add "icon:$icon" into my script.

Essentially I would like to:

var marker1 = new google.maps.Marker({

// is IE version less than 9 add this
                  icon: $icon,
// else do nothing
                  position: new google.maps.LatLng(-45.03145, 168.660030),
                  map: map,
                  title: "Some Title"


Cheers,
N
0
Neil_Bradley
Asked:
Neil_Bradley
  • 2
2 Solutions
 
GaryCommented:
What version of jQuery - if below 1.9 then you are in luck.
http://api.jquery.com/jQuery.browser/

Else

var browser= navigator.userAgent.toLowerCase();
version=browser.indexOf('msie') != -1?parseInt(browser.split('msie')[1]) : false;
if(version<9){
// IE8 and lower
}

Open in new window

(untested - should work)
0
 
leakim971PluritechnicianCommented:
Try this :
var markerOptions = {
                  icon: $icon,
                  position: new google.maps.LatLng(-45.03145, 168.660030),
                  map: map,
                  title: "Some Title"
};
var IE = navigator.userAgent.match(/MSIE\s(\d.\d)/);
if( (IE && IE.pop() * 1>=9) || !IE ) delete markerOptions["icon"];
var marker1 = new google.maps.Marker(markerOptions);

Open in new window

0
 
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Great work! The solutions worked very well.
Pity I had to roll back my version of jquery to make this work as ts a really hand tool!
N
0
 
leakim971PluritechnicianCommented:
Pity I had to roll back my version of jquery to make this work as ts a really hand tool!

Was not the right thing to do...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now