tags:

views:

79

answers:

4

How can I tell if a given javascript function will work across browsers? For instance, I want to use String.trim() and I see that it works in Firefox, but will it work in all the other major browsers? I imagine there is a good doc online somewhere, but I can't find it.

+3  A: 

Try quirksmode, for starters: http://quirksmode.org

Pointy
Does quirksmode provide compatibility info for core JavaScript functions, i.e not just DOM object methods?
Donal Boyle
No, to be honest it's mostly DOM stuff. See the answer @CMS gave.
Pointy
+1  A: 

The book Dynamic HTML The Definitive Reference by Danny Goodman is a huge help for this type of research.

For example, for the function String.replace(), it tells me it is supported by the following browsers and versions (since): IE 4, NN 4, Moz all, Saf all, Op 7, and has been included in ECMA 3.

Donal Boyle
I purchased the first and second editions of this and for years it was rarely off my desk, however isn't it a bit out of date now? I can't see a new edition on Amazon. +1 anyway for a classic.
Cruachan
There's a third edition that came out 2-3 years ago. As a reference it's OK. As a guide to writing JavaScript I'd take it with a large pinch of salt.
Tim Down
+3  A: 

QuirksMode can give you information but mostly about CSS and DOM.

String.prototype.trim is a new method, from the ECMAScript 5th Edition Standard.

To check the availability of the new ES5 methods on various browsers, give a look to the following table:

Usually if you are checking which built-in standard methods are available and work propertly across browsers, you can run conformance tests:

CMS
That's true - there's not much at Quirksmode about the Javascript standard classes.
Pointy
@Pointy yep, they focus on W3C standards, DOM Core, Events, CSS, etc... but not too much on the built-in ECMA-262 features.
CMS
+1  A: 

Check out the W3Schools JavaScript site, especially the complete references for the various objects. As an example, here's the complete String reference.

Hank Gay