[Javascript] [JavaScript List] getElementsByClass probs

XtiaN indotekken at yahoo.com
Tue Jul 11 04:59:47 CDT 2006


hi guys, i've problem here.. i want to make pop up window from my a href links using unobtrusive js.
but it doesn't work...

code in my html
<head>
<script type="text/javascript">
addLoadEvent(function() {
findBT2('btnym','/member/includes/popupym.html','200','100');
findBT2('btnmsn','/member/includes/popupmsn.html','200','100');
}
</script>
</head>
....
<a href="#" class="btnym">link</a>
<a href="#" class="btnmsn">link</a>
...

external js:

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//dustindiaz
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function findBT2(btnClass,what,width,height){
    var btn = getElementsByClass(btnClass,document,'*');
    //alert(btn);
    btn.onclick = function() {
        window.open(what, 'title', 'width='+width+',height='+height+'');
        return(false);
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20060711/63e8e7ef/attachment.htm>


More information about the Javascript mailing list