Solved

test for ie in jquery

Posted on 2014-03-14
4
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

730 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