Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads
Add your own
alternative version

xLibrary - Using a custom IHttpHandler to access embedded JavaScript

, 28 Feb 2009
This article covers how to make a custom IHttpHandler to use the X Library from embedded in an assembly.
<?xml version="1.0" encoding="ISO-8859-1"?>

<x_symbol id='xGetElementsByTagName'>


<copyright>Copyright 2002-2007 Michael Foster (</copyright>
<license>Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL</license>

<description><![CDATA[Returns an array of elements which are descendants of parentEle and have tagName. If parentEle is null or not present, document will be used. If tagName is null or not present, "*" will be used.]]></description>

<syntax>xGetElementsByTagName(tagName[, parentEle])</syntax>

    <name>parentEle</name><note><![CDATA[element reference]]></note>

<return>node list</return>


    <note><![CDATA[Index of all X demos.]]></note>

I'm now using the new function as this symbol's src.
The original function was as follows:
[code]function xGetElementsByTagName(t,p)
  var list = null;
  t = t || '*';
  p = p || document;
  if (xIE4 || xIE5) {
    if (t == '*') list = p.all;
    else list = p.all.tags(t);
  else if (p.getElementsByTagName) list = p.getElementsByTagName(t);
  return list || new Array();
After a discussion with Hallvord on the Opera libraries list on
how to eliminate the browser sniff...

I really like the change - but I don't like the code-size increase (about 50 bytes).
I realize that my additions contributed to the size increase - but I felt they
were needed to maintain the semantics of the original function. Perhaps they
could be optimized.
My change to your expression: (t=='*' && list.length == 0)
to this: (t=='*' && (!list || !list.length))
is perhaps needless paranoia - I don't know 
So we reduced the browser sniff assumption to an assumption (or knowledge) about
the effect of the bug - with this expression: (t=='*' && (!list || !list.length)).
Excellent!  And perhaps the increase of 50 bytes is worth it - knowing
that I won't have to maintain a browser sniff for this function.
    <note><![CDATA[This even works with IE4. It also fixes the IE5 '*' bug.]]></note>

    <note><![CDATA[In IE, typeof p.getElementsByTagName is 'unknown'.]]></note>
    <note><![CDATA[See comment for 19Oct06.]]></note>
    <note><![CDATA[Reduced 93 bytes]]></note>
    <note><![CDATA[put in it's own file for use with XC]]></note>


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Rick Bassham
Software Developer (Senior)
United States United States
I have been a software developer since 2005, focusing on .Net applications with MS SQL backends, and recently, C++ applications in Linux, Mac OS X, and Windows.
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 28 Feb 2009
Article Copyright 2007 by Rick Bassham
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid