I had several clients complain yesterday that some code stopped working. Apparently it comes down to plug-ins using the now deprecated jQuery.browser
which stopped working yesterday when jQuery 1.9 was released.
I (quickly) looked at the 1.9 change docs and it seems like they want me to substitute some pretty heavy libraries just for that one function.
Is there a recommended lightest weight plug-in or code snippet to restore that functionality?
For what these sites need, it's very basic; I only need the most basic detection of IE vs FF vs everyone else.
Suggestions?
I've use the following code answered by Alexx Roche, but i wanted to detect MSIE so:
<script type="text/javascript">
$(document).ready(function() {
if (navigator.userAgent.match(/msie/i) ){
alert('I am an old fashioned Internet Explorer');
}
});
</script>
hope it helps!
jQuery Migrate was created to allow for backwards compatibility while you update your code.
https://github.com/jquery/jquery-migrate
As a bonus, it logs deprecated functions as you use them. I would give it a try while you resolve the problems. Also, you should be setting a specific version of jQuery for your sites. It's good to upgrade, but be sure to test those upgrades before putting them in production. If you are using a CDN, you can still specify a specific version in the file name.
Now, you don't need a jQuery plugin for what you are asking. Check out the navigator
object.
appCodeName: "Mozilla"
appName: "Netscape"
appVersion: "5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17"
cookieEnabled: true
doNotTrack: null
geolocation: Geolocation
language: "en-US"
mimeTypes: MimeTypeArray
onLine: true
platform: "MacIntel"
plugins: PluginArray
product: "Gecko"
productSub: "20030107"
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17"
vendor: "Google Inc."
vendorSub: ""
var browser = {
chrome: false,
mozilla: false,
opera: false,
msie: false,
safari: false
};
var sUsrAg = navigator.userAgent;
if(sUsrAg.indexOf("Chrome") > -1) {
browser.chrome = true;
} else if (sUsrAg.indexOf("Safari") > -1) {
browser.safari = true;
} else if (sUsrAg.indexOf("Opera") > -1) {
browser.opera = true;
} else if (sUsrAg.indexOf("Firefox") > -1) {
browser.mozilla = true;
} else if (sUsrAg.indexOf("MSIE") > -1) {
browser.msie = true;
}
console.log(browser.msie);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With