During the last few weeks, while building HTML Applications (HTAs), I encountered some snags that have caused me to stop and think more about exactly how browsers interpret markup and scripts. In dealing with the latter, this article will highlight some of the ramifications of mixing scripting languages in your web pages. Although these discussions will be applicable to cross-browser scripting in general, many of the points will be relevant to HTAs as well.
In typical cross-browser fashion, the else if checks for the JScript
function. Testing for the existence of a function or attribute has replaced
browser sniffing techniques, as the introduction of newer browsers has made
that technique unreliable. In either case, the result is functions that are
The following page demonstrates how browsers will only run the languages that
they support. Hence, Firefox and Opera ignore JScripts and VBScripts, while
IE runs all of them:
The Default Scripting Language
type="text/vbscript"attribute. This presents a potential issue for pages that contain both JScript and VBScripts. Certainly, the practice of always including
typeattributes in all your scripts is recommended, but it won't necessarily solve your problems because of intrinsic event handlers.
Intrinsic event handlers are sinks that bind scripting code to document elements.
They are triggered when something happens to an element. You can recognize event
handlers by their "on" prefix. Some examples include the
onmouseover, onmouseout, and
onclick events. Unless specified, all intrinsic
event handlers use the default scripting language:
The above code produces the following two alerts; the first in Internet Explorer, the second in Firefox: