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 www.cross-browser.com embedded in an assembly.
xLibrary_demo.zip
xLibraryDemo
App_Data
Bin
xLibrary.dll
xLibrary_src.zip
xLibrary
lib
Properties
<?xml version="1.0" encoding="ISO-8859-1"?>

<x_symbol id='xGetElementsByTagName'>

<sources>
  <src><file>xgetelementsbytagname.js</file><note><![CDATA[Default.]]></note></src>
</sources>

<copyright>Copyright 2002-2007 Michael Foster (Cross-Browser.com)</copyright>
<license>Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL</license>
<groups>
  <grp>DOM</grp>
</groups>
<type>Function</type>

<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>

<parameters>
  <par>
    <name>tagName</name><note><![CDATA[string]]></note>
  </par>
  <par>
    <name>parentEle</name><note><![CDATA[element reference]]></note>
  </par>
</parameters>

<return>node list</return>

<dependencies>
</dependencies>

<demos>
  <demo>
    <url>http://cross-browser.com/toys/</url>
    <note><![CDATA[Index of all X demos.]]></note>
  </demo>
</demos>

<comments>
  <comment>
    <date>19Oct06</date>
    <author>mf</author>
    <note><![CDATA[
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();
}[/code]
    ]]></note>
  </comment>
  <comment>
    <date>2May05</date>
    <author>mf</author>
    <note><![CDATA[
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>
  </comment>
  <comment>
    <date>2002</date><author>mf</author>
    <note><![CDATA[This even works with IE4. It also fixes the IE5 '*' bug.]]></note>
  </comment>
</comments>

<revisions>
  <rev>
    <num>4</num><date>20Dec06</date><author>mf</author>
    <note><![CDATA[In IE, typeof p.getElementsByTagName is 'unknown'.]]></note>
  </rev>
  <rev>
    <num>3</num><date>19Oct06</date><author>mf</author>
    <note><![CDATA[See comment for 19Oct06.]]></note>
  </rev>
  <rev>
    <num>2</num>
    <date>16Mar05</date>
    <author>mf</author>
    <note><![CDATA[Reduced 93 bytes]]></note>
  </rev>
  <rev>
    <num>1</num>
    <date>31Mar04</date>
    <author>mf</author>
    <note><![CDATA[put in it's own file for use with XC]]></note>
  </rev>
</revisions>

</x_symbol>
  

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.

License

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