Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15065
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Best way to feature-test? |
| Date | 2012-07-16 10:48 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <ju0kh6$itl$1@dont-email.me> (permalink) |
| References | <9279c95c-914c-4a92-aa23-495f81bccc1a@googlegroups.com> |
Am 2012-07-16 02:50, perryv@gmail.com meinte:
> Hi everyone,
>
> I've been using the following technique to detect if a certain functionality is supported by a browser:
>
>
> if(document.someFunctionality) {
> // Use someFunctionality
> }
>
> But lately, I've been reading that "document", "window" and other browser objects are "host objects", and host objects have their own rules and behaviors that depend on the browser and the platform. So it's possible that merely testing "document.someFunctionality" can throw an exception in some browser on some platform.
>
> So, in order to cover those cases, is it reasonable to do the following?
>
> if(typeof document.someProperty != 'undefined') {
> // Go ahead and use the property
> }
>
> if(typeof document.someFunction == 'function') {
> // Go ahead and invoke "document.someFunction()"
> }
>
> Or is it overkill?
Quite the contrary.
Some links for further reading:
<http://www.cinsoft.net/host.html>
<http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting>
Gregor
--
http://vxweb.net
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best way to feature-test? perryv@gmail.com - 2012-07-15 17:50 -0700
Re: Best way to feature-test? perryv@gmail.com - 2012-07-15 17:54 -0700
Re: Best way to feature-test? Gregor Kofler <usenet@gregorkofler.com> - 2012-07-16 10:48 +0200
Re: Best way to feature-test? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-16 21:29 +0200
Re: Best way to feature-test? Ivan The Not-So-Bad <1suf41n@yahoo.com> - 2012-07-16 13:49 +0000
Re: Best way to feature-test? Tim Down <timdown@gmail.com> - 2012-07-16 08:42 -0700
Re: Best way to feature-test? Ivan The Not-So-Bad <1suf41n@yahoo.com> - 2012-07-16 17:35 +0000
Re: Best way to feature-test? Jim T. <x@y.z> - 2012-07-18 13:22 -0400
Re: Best way to feature-test? Jim T. <x@y.z> - 2012-07-18 13:24 -0400
csiph-web