<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Detecting event support in browsers</title>
	<atom:link href="http://ajaxian.com/archives/detecting-event-support-in-browsers/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/detecting-event-support-in-browsers</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272558</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Mon, 06 Apr 2009 09:03:01 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272558</guid>
		<description>@kangax, I wrote directly in the textarea without testing, that was just an idea and dunno why I used undefined but it is irrelevant since that is just a &quot;somehow cache it&quot; suggestion :)</description>
		<content:encoded><![CDATA[<p>@kangax, I wrote directly in the textarea without testing, that was just an idea and dunno why I used undefined but it is irrelevant since that is just a &#8220;somehow cache it&#8221; suggestion :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanMorr</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272549</link>
		<dc:creator>RyanMorr</dc:creator>
		<pubDate>Sun, 05 Apr 2009 16:02:34 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272549</guid>
		<description>@dperini
I&#039;d heard of DOMFrameContentLoaded before, but again, although it is very likely that a browser that supports DOMFrameContentLoaded also supports DOMContentLoaded, it is an assumption. As I said in the last comment, there is only one place where detecting DOMContentLoaded would be necessary and that can already be achieved without browser detection.

Thanks for all the info, I honestly didn&#039;t expect such a response. I&#039;ll be sure to post a link to my solution once its finished (as part of a larger project) sometime this week. No doubt it will include many of the great ideas discussed here!</description>
		<content:encoded><![CDATA[<p>@dperini<br />
I&#8217;d heard of DOMFrameContentLoaded before, but again, although it is very likely that a browser that supports DOMFrameContentLoaded also supports DOMContentLoaded, it is an assumption. As I said in the last comment, there is only one place where detecting DOMContentLoaded would be necessary and that can already be achieved without browser detection.</p>
<p>Thanks for all the info, I honestly didn&#8217;t expect such a response. I&#8217;ll be sure to post a link to my solution once its finished (as part of a larger project) sometime this week. No doubt it will include many of the great ideas discussed here!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dperini</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272546</link>
		<dc:creator>dperini</dc:creator>
		<pubDate>Sun, 05 Apr 2009 02:49:29 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272546</guid>
		<description>@RyanMorr,
in newer W3C browser you can find a &quot;DOMFrameContentLoaded&quot; event which can be feature tested...and I believe it also makes more sense to have the controller of these events in a centralized location instead of inside each iframes, obviously if you have control over them.</description>
		<content:encoded><![CDATA[<p>@RyanMorr,<br />
in newer W3C browser you can find a &#8220;DOMFrameContentLoaded&#8221; event which can be feature tested&#8230;and I believe it also makes more sense to have the controller of these events in a centralized location instead of inside each iframes, obviously if you have control over them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272543</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Sat, 04 Apr 2009 22:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272543</guid>
		<description>@WebReflection

Good idea about caching - no need to recreate an element, set its attribute, etc. Btw, that&#039;s an interesting way to check for `undefined` value you&#039;ve got there. Is `typeof`not in style these days? : ) 

I would actually just use `in` operator (it would, of course, return `Object.prototype.*` properties, but so would `=== undefined` check; in any case, those are probably not important in this particular case) - `&quot;eventName&quot; in cache`

@RyanMorr
I&#039;m not very familiar with DOMContentLoaded intrincancies, but shouldn&#039;t it be possible to create a dummy context (i.e. iframe) and check if it fires on a document in that context?

Regarding association of events and element types, that&#039;s an excellent point you raise there. Now that I think about it, an inference used in my original version could very well be too weak. A browser might be able to fire/listen for, say, &quot;load&quot; events on IFRAME&#039;s but not on IMG&#039;s. I wonder if there actually are browsers with such deficiencies out there.</description>
		<content:encoded><![CDATA[<p>@WebReflection</p>
<p>Good idea about caching &#8211; no need to recreate an element, set its attribute, etc. Btw, that&#8217;s an interesting way to check for `undefined` value you&#8217;ve got there. Is `typeof`not in style these days? : ) </p>
<p>I would actually just use `in` operator (it would, of course, return `Object.prototype.*` properties, but so would `=== undefined` check; in any case, those are probably not important in this particular case) &#8211; `&#8221;eventName&#8221; in cache`</p>
<p>@RyanMorr<br />
I&#8217;m not very familiar with DOMContentLoaded intrincancies, but shouldn&#8217;t it be possible to create a dummy context (i.e. iframe) and check if it fires on a document in that context?</p>
<p>Regarding association of events and element types, that&#8217;s an excellent point you raise there. Now that I think about it, an inference used in my original version could very well be too weak. A browser might be able to fire/listen for, say, &#8220;load&#8221; events on IFRAME&#8217;s but not on IMG&#8217;s. I wonder if there actually are browsers with such deficiencies out there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanMorr</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272541</link>
		<dc:creator>RyanMorr</dc:creator>
		<pubDate>Sat, 04 Apr 2009 17:48:41 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272541</guid>
		<description>@dperini
True enough, I was able to test for almost all mutation events. I suppose I was just eluding to DOMContentLoaded, there is no reliable test for that considering it only fires once. 

@WebReflection
I like the idea of caching, of course there needs to be some type of element or node inference, considering an onload event can fire on an image, iframe, or the window itself.</description>
		<content:encoded><![CDATA[<p>@dperini<br />
True enough, I was able to test for almost all mutation events. I suppose I was just eluding to DOMContentLoaded, there is no reliable test for that considering it only fires once. </p>
<p>@WebReflection<br />
I like the idea of caching, of course there needs to be some type of element or node inference, considering an onload event can fire on an image, iframe, or the window itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272539</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Sat, 04 Apr 2009 10:39:37 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272539</guid>
		<description>Gosh!!!! cache[eventName] !== undefined ...</description>
		<content:encoded><![CDATA[<p>Gosh!!!! cache[eventName] !== undefined &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272538</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Sat, 04 Apr 2009 10:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272538</guid>
		<description>oops, couple of typos (I should stop to write code in textareas :D)
&lt;code&gt;var isEventSupported = (function(cache, undefined){
    var TAGNAMES = {
      &#039;select&#039;:&#039;input&#039;,&#039;change&#039;:&#039;input&#039;,
      &#039;submit&#039;:&#039;form&#039;,&#039;reset&#039;:&#039;form&#039;,
      &#039;error&#039;:&#039;img&#039;,&#039;load&#039;:&#039;img&#039;,&#039;abort&#039;:&#039;img&#039;
    };
    function isEventSupported(eventName) {
      if(cache[eventName] === undefined)
          return cache[eventName];
      var el = document.createElement(TAGNAMES[eventName] &#124;&#124; &#039;div&#039;);
      eventName = &#039;on&#039; + eventName;
      var isSupported = (eventName in el);
      if (!isSupported) {
        el.setAttribute(eventName, &#039;return;&#039;);
        isSupported = typeof el[eventName] == &#039;function&#039;;
      };
      el = null;
      return cache[eventName] = isSupported;
    };
    return isEventSupported;
})({});&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>oops, couple of typos (I should stop to write code in textareas :D)<br />
<code>var isEventSupported = (function(cache, undefined){<br />
    var TAGNAMES = {<br />
      'select':'input','change':'input',<br />
      'submit':'form','reset':'form',<br />
      'error':'img','load':'img','abort':'img'<br />
    };<br />
    function isEventSupported(eventName) {<br />
      if(cache[eventName] === undefined)<br />
          return cache[eventName];<br />
      var el = document.createElement(TAGNAMES[eventName] || 'div');<br />
      eventName = 'on' + eventName;<br />
      var isSupported = (eventName in el);<br />
      if (!isSupported) {<br />
        el.setAttribute(eventName, 'return;');<br />
        isSupported = typeof el[eventName] == 'function';<br />
      };<br />
      el = null;<br />
      return cache[eventName] = isSupported;<br />
    };<br />
    return isEventSupported;<br />
})({});</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dperini</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272537</link>
		<dc:creator>dperini</dc:creator>
		<pubDate>Sat, 04 Apr 2009 10:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272537</guid>
		<description>@RyanMorr,
you can test each one of the Mutation Events separately without inferring anything if you prefer so, as you said relying only on &quot;.hasFeature()&quot; may misrepresent real browser capabilities.

One example is FF2 were some of the Mutation Events exists and work well enough but are not shown through the &quot;.implementation&quot; interface.</description>
		<content:encoded><![CDATA[<p>@RyanMorr,<br />
you can test each one of the Mutation Events separately without inferring anything if you prefer so, as you said relying only on &#8220;.hasFeature()&#8221; may misrepresent real browser capabilities.</p>
<p>One example is FF2 were some of the Mutation Events exists and work well enough but are not shown through the &#8220;.implementation&#8221; interface.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272536</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Sat, 04 Apr 2009 10:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272536</guid>
		<description>@kangax
good stuff. About the name, isEventAvailable ? I am just concerned about this function expensiveness and I wonder if a simple cache implementation could make things better for everybody. Something like:
&lt;code&gt;
var isEventSupported = (function(cache){
    var TAGNAMES = {
      &#039;select&#039;:&#039;input&#039;,&#039;change&#039;:&#039;input&#039;,
      &#039;submit&#039;:&#039;form&#039;,&#039;reset&#039;:&#039;form&#039;,
      &#039;error&#039;:&#039;img&#039;,&#039;load&#039;:&#039;img&#039;,&#039;abort&#039;:&#039;img&#039;
    };
    function isEventSupported(eventName) {
      if(cache[eventName])
          return cache[eventName];
      var el = document.createElement(TAGNAMES[eventName] &#124;&#124; &#039;div&#039;);
      eventName = &#039;on&#039; + eventName;
      var isSupported = (eventName in el);
      if (!isSupported) {
        el.setAttribute(eventName, &#039;return;&#039;);
        isSupported = typeof el[eventName] == &#039;function&#039;;
      };
      el = null;
      return isSupported;
    }
    return cache[eventName] = isEventSupported;
})({});
&lt;/code&gt;
basically the same size, theoretically no side effects, performances improved. What do you think?</description>
		<content:encoded><![CDATA[<p>@kangax<br />
good stuff. About the name, isEventAvailable ? I am just concerned about this function expensiveness and I wonder if a simple cache implementation could make things better for everybody. Something like:<br />
<code><br />
var isEventSupported = (function(cache){<br />
    var TAGNAMES = {<br />
      'select':'input','change':'input',<br />
      'submit':'form','reset':'form',<br />
      'error':'img','load':'img','abort':'img'<br />
    };<br />
    function isEventSupported(eventName) {<br />
      if(cache[eventName])<br />
          return cache[eventName];<br />
      var el = document.createElement(TAGNAMES[eventName] || 'div');<br />
      eventName = 'on' + eventName;<br />
      var isSupported = (eventName in el);<br />
      if (!isSupported) {<br />
        el.setAttribute(eventName, 'return;');<br />
        isSupported = typeof el[eventName] == 'function';<br />
      };<br />
      el = null;<br />
      return isSupported;<br />
    }<br />
    return cache[eventName] = isEventSupported;<br />
})({});<br />
</code><br />
basically the same size, theoretically no side effects, performances improved. What do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanMorr</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272532</link>
		<dc:creator>RyanMorr</dc:creator>
		<pubDate>Fri, 03 Apr 2009 22:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272532</guid>
		<description>@kangax
Sorry I should have been more descriptive. I am aware of the ability to test for some of the mutation events. However I don&#039;t like the idea of inferring support for one event simply because a similar one exists, for instance, assuming DOMContentLoaded is supported because DOMAttrModified is.</description>
		<content:encoded><![CDATA[<p>@kangax<br />
Sorry I should have been more descriptive. I am aware of the ability to test for some of the mutation events. However I don&#8217;t like the idea of inferring support for one event simply because a similar one exists, for instance, assuming DOMContentLoaded is supported because DOMAttrModified is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272531</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Fri, 03 Apr 2009 21:49:06 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272531</guid>
		<description>Thanks everyone.

@unscriptable
You can definitely improvise with it :) My example only explains an idea.

@digitarald
Yes, `isAvailable` would probably be a better name. Unfortunately, testing for an actual event behavior is often too obtrusive (as I mentioned in the post). 

@RyanMorr
Exactly which mutation events were you not able to feature test? Diego&#039;s NWMatcher has great examples of some of the checks.</description>
		<content:encoded><![CDATA[<p>Thanks everyone.</p>
<p>@unscriptable<br />
You can definitely improvise with it :) My example only explains an idea.</p>
<p>@digitarald<br />
Yes, `isAvailable` would probably be a better name. Unfortunately, testing for an actual event behavior is often too obtrusive (as I mentioned in the post). </p>
<p>@RyanMorr<br />
Exactly which mutation events were you not able to feature test? Diego&#8217;s NWMatcher has great examples of some of the checks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dperini</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272528</link>
		<dc:creator>dperini</dc:creator>
		<pubDate>Fri, 03 Apr 2009 20:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272528</guid>
		<description>@RyanMorr,
event names are enumerated on the native &quot;Event&quot; Object for Firefox, Safari and Konqueror. This allows to query for individual event names.

&quot;MOUSEOVER&quot; in Event; // will be true in those browsers

For IE and Opera no other way except using kangax proposal.

@kangax
thank you for sharing such useful informations.</description>
		<content:encoded><![CDATA[<p>@RyanMorr,<br />
event names are enumerated on the native &#8220;Event&#8221; Object for Firefox, Safari and Konqueror. This allows to query for individual event names.</p>
<p>&#8220;MOUSEOVER&#8221; in Event; // will be true in those browsers</p>
<p>For IE and Opera no other way except using kangax proposal.</p>
<p>@kangax<br />
thank you for sharing such useful informations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanMorr</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272522</link>
		<dc:creator>RyanMorr</dc:creator>
		<pubDate>Fri, 03 Apr 2009 16:12:36 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272522</guid>
		<description>I was beaten to the punch, I was literally a week away from my own version of this very function. My solution utilizes the createEventObject and fireEvent methods for IE - which throws an error for unsupported events.

I never thought to use the &quot;in&quot; keyword for object inference to support events. Grea work!!! I may have to borrow some of these techniques for my release, I&#039;ll give full credit of course.

The only problem is with those pesky Mutation events, could use document.implementation.hasFeature to detect it as a whole but I&#039;d prefer something to detect the events individually.

Any ideas?</description>
		<content:encoded><![CDATA[<p>I was beaten to the punch, I was literally a week away from my own version of this very function. My solution utilizes the createEventObject and fireEvent methods for IE &#8211; which throws an error for unsupported events.</p>
<p>I never thought to use the &#8220;in&#8221; keyword for object inference to support events. Grea work!!! I may have to borrow some of these techniques for my release, I&#8217;ll give full credit of course.</p>
<p>The only problem is with those pesky Mutation events, could use document.implementation.hasFeature to detect it as a whole but I&#8217;d prefer something to detect the events individually.</p>
<p>Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: digitarald</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272520</link>
		<dc:creator>digitarald</dc:creator>
		<pubDate>Fri, 03 Apr 2009 14:34:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272520</guid>
		<description>Looks more like a isAvailable check. The existing property does not indicate that the event can be used in the browser, just see all the *buggy* and *incomplete* states in http://www.quirksmode.org/dom/events/index.html</description>
		<content:encoded><![CDATA[<p>Looks more like a isAvailable check. The existing property does not indicate that the event can be used in the browser, just see all the *buggy* and *incomplete* states in <a href="http://www.quirksmode.org/dom/events/index.html" rel="nofollow">http://www.quirksmode.org/dom/events/index.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spocke</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272518</link>
		<dc:creator>Spocke</dc:creator>
		<pubDate>Fri, 03 Apr 2009 13:53:41 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272518</guid>
		<description>This is really neat! I&#039;ve noticed the function wrapper when I serialize the dom in TinyMCE but I never figured that it could be used for a feature detection. This would be very helpful to detect browser specific events like onmouseenter etc.</description>
		<content:encoded><![CDATA[<p>This is really neat! I&#8217;ve noticed the function wrapper when I serialize the dom in TinyMCE but I never figured that it could be used for a feature detection. This would be very helpful to detect browser specific events like onmouseenter etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: unscriptable</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers/comment-page-1#comment-272517</link>
		<dc:creator>unscriptable</dc:creator>
		<pubDate>Fri, 03 Apr 2009 13:08:58 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6487#comment-272517</guid>
		<description>Excellent work (as usual), kangax!  Like many others, I couldn&#039;t work-out a good cross-browser solution like this. 

It&#039;s too bad we have to create/destroy an element to do the check.  I think I&#039;d typically be working with an existing element when I wanted to determine event support (but not always, I guess).  It looks pretty straightforward to extend this function to pass in an optional test element, rather than create one.

function isEventSupported(eventName, el) {
      el = el &#124;&#124; document.createElement(TAGNAMES[eventName] &#124;&#124; &#039;div&#039;);
    //...
}</description>
		<content:encoded><![CDATA[<p>Excellent work (as usual), kangax!  Like many others, I couldn&#8217;t work-out a good cross-browser solution like this. </p>
<p>It&#8217;s too bad we have to create/destroy an element to do the check.  I think I&#8217;d typically be working with an existing element when I wanted to determine event support (but not always, I guess).  It looks pretty straightforward to extend this function to pass in an optional test element, rather than create one.</p>
<p>function isEventSupported(eventName, el) {<br />
      el = el || document.createElement(TAGNAMES[eventName] || &#8216;div&#8217;);<br />
    //&#8230;<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

