Solved

test for ie in jquery

Posted on 2014-03-14
4
219 Views
Last Modified: 2014-03-16
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
Comment
Question by:Neil_Bradley
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 300 total points
ID: 39930775
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
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 200 total points
ID: 39930788
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
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 39932865
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39932868
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question