On Nov 23, 12:43 am, "Rémi Grumeau" <[email protected]> wrote: [...] > >>> Not only does the above demonstrate that typeof tests on host > >>> objects > >>> and properties are unreliable, but also that IE is the one > >>> behaving as > >>> you expect and some other "decent" browser is misbehaving. > > >> `typeof anObject.nonExistentProperty` --> "undefined" is ok. > > > But some browsers return "object" for listener properties that have > > not been set. So testing for support of events using typeof tests on > > related host object properties is unreliable. I think you are agreeing > > with me. > > Sure! > As you know, this list is called iphonewebdev, which means that what > we you'll find here / ppl will publish could be wrong on desktop > browser. The thing is: for iPhone web dev, it works.
Robust library development should deal with likely future issues if they are easily identifiable and can be avoided. While the code "works" in one browser, it can be expected to fail in other (possibly future) browsers with reasonable confidence. Desktop browsers provide alternative environments that likely will be replicated on mobile devices, it makes sense to analyse and deal with issues that are likely to arise if the time and effort to do so is minimal (as it is in this case). It is the same reason it is good to test desktop browser scripts in old browsers. If they fail gracefully (i.e. just don't implement unsupported features rather than crash), that is usually sufficient. > The result ofhttp://www.we-are-gurus.com/labs/onorientation-test.html > is > Desktop > - Safari : 'undefined' > - Chrome : 'undefined' > - Firefox : 'undefined' > - Internet Explorer : 'undefined' > - Opera : 'undefined' > > Smartphones / Tablets > - iOS (2, 3 & 4) : 'number' > - Android : 'number' > - Blackberry OS6 : 'number' > - Palm WebOS : 'undefined' > > http://cl.ly/111r25202T3B1d153722 > :) Which really doesn't prove anything in regard to support for the orientationchange event. > So i guess the best test would be > if (typeof window.orientation == "number") { > // supported > > } else { > // not supported > } Just because there is a window.orientation property that isn't undefined doesn't mean that the orientationchange event is supported. If the issue is to deal with lack of support for the orientationchange event, one has to consider whether it is better to use an unreliable feature test that may remove functionality from browsers that actually support it, or to set a listener that may never be called. If the page must deal with both orientations anyway, why not employ the latter strategy until a more suitable test is available? If the test is unreliable, why make it available? > Toughts? You may find these threads interesting: Ontouchstart <URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/e7a70a39b22839de/5a729a399ea7ad25?lnk=gst&q=Detecting+support+for+event+types#5a729a399ea7ad25 > Detecting support for event types <URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/93e05bc723164080/ec2b0481c0f10260?lnk=gst&q=Detecting+support+for+event+types#ec2b0481c0f10260 > Some code consistent with the discussions above written by Kangax: <URL: http://kangax.github.com/iseventsupported/ > The original test used window.onorientationchange. However as the window object doesn't support setAttribute, an alternative is to use a body element. Using kangax's isSupported() with a body element and orientationchange event produces "false" in Firefox and "true" in IE 6 (I suspect IE 6 doesn't actually support it) so likely isn't useful here (again, presuming that the quirks of desktop browsers are carried over to their mobile equivalents). Windows Phone 7 is now being heavily marketed, time to start testing to see how much of IE desktop made it into the mobile version. :-) -- Rob -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
