Solved

test for ie in jquery

Posted on 2014-03-14
4
218 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)

786 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