Solved

test for ie in jquery

Posted on 2014-03-14
4
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now