jquery $.browser removed - code issue - javascript

I updated my jQuery from 1.3.2 to latest 2.1.0
Now I noticed I have this error on my page:
TypeError: Cannot read property 'safari' of undefined
And here is my code that has this:
if(p=='marginRight'&&$.browser.safari)
and
if($.browser.safari){this.buttons(false,false);
I read that from version 1.9 $.browser has been removed, can somebody please help, how can this be fixed? I googled and tried some things but didn't seem to find the right thing..
Thank you

you can detect browsers via native navigator object
if(navigator.userAgent.indexOf("Safari") > -1) {
// safari
}

The easiest way is to just include jquery-migrate. This patches in all the functions they removed.
Otherwise, you have to rewrite your code to avoid browser detection. Generally, feature detection is recommended over browser sniffing.

The jQuery.browser() method has been deprecated since jQuery 1.3 and
is removed in 1.9. If needed, it is available as part of the jQuery
Migrate plugin. We recommend using feature detection with a library
such as Modernizr.
Reference: http://jquery.com/upgrade-guide/1.9/#jquery-browser-removed
Since it has been removed your most simple option here is to use jquery migrate

Related

Make website support older browsers jQuery calls

I'm a bit stuck here. I have a website that currently uses jQuery 2.1.4 only. I just figured out it won't support older browsers such as IE 6, 7 and 8. I use jQuery for many things in my website, which includes login system, live chat and some management functions.
Anyway, I was thinking of implementing jQuery 1.11.3 because it supports these browsers. Thing is, I don't really know where to start from because I don't think I simply add another script source for jQuery 1.11.3 and it shall fix it all, but I'm looking for a way to add it so I won't have to change all my functions or add special functions just for older browsers.
The only jQuery methods I use are $.ajax, $.when and $.then.
I don't think I simply add another script source for jQuery 1.11.3 and it shall fix it all
You just replace the existing script source with it.
The 2.1.x branch is just the 1.11 branch with all the slow compatibility code for old browsers removed. They are API compatible.

Jquery Carousel getting error: "Cannot read property 'safari' of undefined"

I have installed a duplicate of my site on a dev directory and have discover jQuery Carousel is no longer working.
I now get the error:
Uncaught TypeError: Cannot read property 'safari' of undefined
I don't understand this as I am testing on Chrome and Firefox.
Furthermore, this error is not occurring on the production version of the site - only the dev version.
I have updated jQuery, jQuery-UI and the version of jQuery Carousel as well as testing that all files are present but the problem persists.
Would anyone know what's going on and how to fix it?
My Carousel code is:
jQuery(document).ready(function($){
$('#mycarousel').jcarousel({
vertical: true,
scroll: 2
});
});
And if any wants a look a dev version of the site is here: http://www.dev.wakeup.com.au/
The problem might be that the plugin uses $.browser.
This has been deprecated and removed in jQuery version 1.9, as stated in their upgrade logs:
http://api.jquery.com/jquery.browser/
Description: Contains flags for the useragent, read from
navigator.userAgent. This property was removed in jQuery 1.9 and is
available only through the jQuery.migrate plugin. Please try to use
feature detection instead.
If this is the case, the plugin uses the (frowned-upon) browser sniffing techniques to achieve cross browser compatibility.
You might test the plugin with a version of jQuery before 1.9. If you need a newer version of jQuery, have a look at the plugin's page if there are any new versions available that fix this incompatibility with new jQuery versions.

jQuery 1.7 is *still* returning the event.layerX and event.layerY error in Chrome

What am I doing wrong? Am I misunderstanding the problem or is it something else entirely?
On my page I was using jQuery 1.6.4 from the Google CDN. This would, of course, generate the error:
event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.
I read here that jQuery 1.7 removed this issue. However, after updating my application to 1.7, I'm still seeing it. I'm using the Microsoft CDN until Google put the link up.
Things I've tried before posting this:
Clearing the browser cache
Changing back to jQuery 1.6.4 (still happens - obviously)
Using jQuery 1.7-specific code to make sure 1.7 is actually being loaded - .on() works fine when I use 1.7 but obviously gives undefined errors with 1.6.4 - I thought this should prove 1.7 is actually running
Commenting out and removing all other Javascript from my application - everything except for jQuery 1.7. Still triggers the error.
Any ideas?
Worked it out - it wasn't immediately obvious either, but posting this here for anyone who gets tripped up by this in future:
It was a Chrome Extension that used an old version of jQuery causing the issue. Disabling all Extensions and re-enabling one at a time helped me find the perpetrator. Hope this helps for anyone else with this issue in the future!

How should one link to a jQuery library: always link to the latest library or not?

What happened is that we have a page that was previously working then all of sudden some scripts no longer work (for some reason). We figured out that we needed to use the latest jQuery library to fix the problem.
So we were thinking to just link to http://code.jquery.com/jquery-latest.min.js so that it's always updated.
However, we are also aware that if we will always use the latest jQuery library, the new version might cause some problems on other older scripts.
What is the best way to link the jQuery library then to minimize these types of issues?
Save the stable version of the library to your local/server and link to it. That's all.
It is a bad idea to link to http://code.jquery.com/jquery-latest.min.js
Jquery latest version always available in,
http://code.jquery.com/jquery-latest.js
For Latest Min Jquery, use
http://code.jquery.com/jquery-latest.min.js
To get latest jquery from other hosts, follow jquerylatest.com

How well does jQuery support backward compatibility?

We have had issues with Mootools not being very backward compatible specifically in the area of drag and drop functionality. I was wondering if anyone has had any similar problems with jQuery not being backward compatible. We are starting to use it quite heavily and are thinking about upgrading to a newer version to start using several plugins that require it. Will we have any issues if we get rid of the older version?
jQuery seems to be nicely backward compatible. I have been using it for more than a couple of years now through several versions of the core and have not had issues when upgrading except a few minor ones with some plugins. I would say that the core seems to be fine but if you're using a lot of plugins you might run into some problems (but these are usually easy to fix, or the new core has that functionality built in anyway so you can just drop them).
jQuery is so serious about backwards compatibility that they produce a "backwards compatibility" plugin for each release: http://docs.jquery.com/Release:jQuery_1.2#jQuery_1.1_Compatibility_Plugin. It let people who don't need backwards compatibility save on page weight.
My experience is that when upgrading, I sometimes find that stuff that used to work breaks. For instance, when upgrading from 1.7.2 to 1.8.3 I found some drag-and-drop features stopped working. Some problems may be due to deprecated jQuery functions being dropped, still in use by incompatible versions of jQuery UI.
Here is a quote from another user:
Backward compatibility may not be the jQuery team’s strong suit, but
as with most things, it’s a work in progress. I’m not meaning to
disparage the great work they do, but it points out the fact that you
simply must always test your scripts with new versions of jQuery.
jQuery has produced backwards compatibility plugins since version 1.0.
Web development has changed a lot over the years, and jQuery has changed along with it. Through all of this time, the team has tried to walk the line between maintaining compatibility with code from the past versus supporting the best web development practices of the present.
The project has the following backwards compatibility repos:
jquery-compat-1.0(Compatibility plugin for those upgrading to jQuery 1.1+ from jQuery 1.0)
jquery-compat-1.1(Compatibility plugin for those upgrading to jQuery 1.2+ from jQuery 1.1)
jquery-xpath(Implement XPath functionality for those upgrading to jQuery 1.2 from jQuery 1.1)
jquery-compat-1.3(Backwards compatibility plugin for jQuery 1.3 (to be used with jQuery 1.4))
jquery-migrate-1.x-stable(Migrate older jQuery code to jQuery 1.9+)
jquery-migrate(Migrate older jQuery code to jQuery 3.0+)
References
jQuery Blog
jQuery Wiki: Won't Fix
jQuery Core Upgrade Guides
jQuery Migrate Plugin - Warning Messages (2.0)
jQuery Migrate Plugin - Warning Messages (3.0)
jqLint
In my experience, jQuery 1.x has been very backwards-compatible until version 1.9.
The jQuery 1.x line had major changes as of jQuery 1.9.0. We strongly recommend that you also use the jQuery Migrate plugin if you are upgrading from pre-1.9 versions of jQuery or need to use plugins that haven't yet been updated. Read the jQuery 1.9 Upgrade Guide and the jQuery 1.9 release blog post for more information.
And don't upgrade to 2.0 until you're sure that this isn't an issue for you:
jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.

Categories

Resources