getElementsByTagName Cross Browse

Description Javascript

This function is a cross-browser version of document.getElementsByTagName.

The Code Download

  1. var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
  2. if(window.opera){
  3.     var i=xUA.indexOf('opera');
  4.     if(i!=-1){
  5.         var v=parseInt(xUA.charAt(i+6));
  6.         xOp7Up=v>=7;
  7.         xOp6Dn=v<7;
  8.     }
  9. } else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
  10.     xIE4Up=parseFloat(navigator.appVersion)>=4;
  11.     xIE4=xUA.indexOf('msie 4')!=-1;
  12.     xIE5=xUA.indexOf('msie 5')!=-1;
  13. } else if(document.layers){
  14.     xNN4=true;
  15. }
  16. xMac=xUA.indexOf('mac')!=-1;
  17.  
  18. function xGetElementsByTagName(t,p){
  19.     var list = null;
  20.     t = t || '*';
  21.     p = p || document;
  22.     if (xIE4 || xIE5) {
  23.         if (t == '*') {
  24.             list = p.all;
  25.     } else {
  26.             list = p.all.tags(t);
  27.         }
  28.     } else if (p.getElementsByTagName) {
  29.         list = p.getElementsByTagName(t);
  30.     }
  31.     return list || new Array();
  32. }

Credits

Added by JC on 13th November 2007

Comments

There are no comments about this snippet.

Post Comment Github Markdown Supported

You must be logged in to post a comment.

Login here to post a comment