Game Development Reference
In-Depth Information
For example, one way to remove a node from the DOM is to call the remove method
on the node itself. However, as of this writing, only a very limited handful of browsers
expose this functionality. Most commonly, browsers allow us to remove a node from
a DOM tree by calling the removeChild method on a parent node, passing a refer-
ence to the child node to be removed from the parent.
The key point to be made here is this; JavaScript itself is very consistent across
browsers, but the way that browsers allow us to programmatically interact with the
DOM, although this is most commonly done via JavaScript, may vary from browser
to browser. While none of this is news to anybody, and certainly is not unique to
HTML5, it is still important to remember that the main tool we have for program-
ming the web platform, that is, JavaScript, is a very powerful and consistent one. The
problem that we need to keep in mind is the DOM API (as well as CSS, although this
particular issue is becoming less and less of an issue, as browsers are beginning to
agree on common standards related to that).
Supporting different browsers
There are different approaches that we can take when developing an HTML5 applic-
ation in order to ensure that the code runs the same in different browsers, and that
the design is rendered the same as well. Some of these practices are painful and
tedious, others are unreliable, and others are simply good enough. Unfortunately, as
long as there are so many browser differences as there are today, there will never
be one single silver bullet that completely makes the problem disappear.
The two main goals when it comes to writing code that runs practically identical in
different browsers are; write as little unique code to each browser as possible, and
write code that degrades gracefully. It is one thing to specifically target a couple of
unique features specific to a particular browser, but it is a completely different issue
to maintain two or more separate code bases. Remember this, that the best code
you can possibly write, both in terms of efficient execution and security, is the code
that you never have to write at all. The more code you write, the more subject to er-
rors and faults your code will be. Thus, avoid writing too much code that does the
same thing as other code you're also writing, but writing it uniquely for a different
browser.
While being a perfectionist can be a great attribute, we must be realistic that we won't
achieve perfection any time soon. Not only that, but in most cases (certainly in all
Search WWH ::




Custom Search