HTML and CSS Reference
In-Depth Information
reset: "form",
error: "img",
load: "img",
abort: "img"
function isEventSupported(eventName) {
var tagName = TAGNAMES[eventName];
var el = document.createElement(tagName
eventName = "on" + eventName;
var isSupported = (eventName in el);
if (!isSupported) {
el.setAttribute(eventName, "return;");
isSupported = typeof el[eventName] == "function";
el = null;
return isSupported;
return isEventSupported;
The method uses an object as look-up for suitable elements to test a given
event on. If no special case is needed, a div element is used. It then tests the two
cases presented above and reports back the result. We'll see an example of using
isEventSupported in Section 10.5, Cross-Browser Event Handlers.
Although the above method is good for a lot of cases, it is unfortunately not
completely infallible. While working on this chapter I was informed by one of my
reviewers, Andrea Giammarchi, that new versions of Chrome claim to support touch
events even when the device running the browser is incapable of firing them. This
means that if you need to test for touch events, you should use additional tests to
verify their existence.
10.4 Feature Testing CSS Properties
If JavaScript is executing, surely CSS will work as well? This is a common assump-
tion, and even though it is likely to be right in many cases, the two features are
entirely unrelated and the assumption is dangerous to make.
In general, scripts should not be overly concerned with CSS and the visual as-
pects of the web page. The markup is usually the best interface between the script
Search WWH ::

Custom Search