IE6 specific Object Doesn't Support ... Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • henryrhenryr
    New Member
    • Jun 2007
    • 103

    IE6 specific Object Doesn't Support ... Error

    Hi All

    I'm using AJAX in an analytics script. All works nicely in Firefox and the script loads my php script which records some information in the database.

    The part with the error in IE is the part which adds the events to the anchor elements. The error message from IE is:

    Line 335: Object doesn't support this property or method.

    The javascript line this refers to (I have confirmed this 100% even though line ref is wrong) is as follows:

    [code=javascript]
    links = document.getEle mentsByTagName( 'a');
    [/code]

    As you can imagine I've tried looking for standard IE bugs for this type of line but nothing comes up.

    Some thoughts I've had: it could be using "links" to name a variable (is links reserved)? It could be that "a" has to be "A". I have tried different combinations of these but no luck.

    Hopefully someone can point me in the right direction!

    Thanks in advance!

    Henry
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That line shouldn't cause errors. Can you post the rest of your code?

    Comment

    • henryrhenryr
      New Member
      • Jun 2007
      • 103

      #3
      Hi

      Thanks for helping out. I thought that might be the case. The relevant code is below. Hopefully it yields some answers...

      [code=javascript]
      /-------------------ANALYTICS--------------------------//
      var xmlHttp; //ajax object
      var vapk; //the visitor pk which is retrieved on entry and used on exit to update
      var listeners = []; //array

      function listenAllLinks( ) {
      if (!document.getE lementsByTagNam e) return false;
      // find links in document
      aLinks = document.getEle mentsByTagName( 'a');

      // if link does have a id add one
      for (var i = 0; i < aLinks.length; i++) {
      addEvent( aLinks[i], 'click', exit, false );
      addEvent( aLinks[i], 'keypress', linkKeyPress, false );
      }

      // find buttons in document
      inputs = document.getEle mentsByTagName( 'input');
      for (var i = 0; i < inputs.length; i++) {
      type = inputs[i].getAttribute(' type');
      // only attach events to buttons
      if ( type == 'submit' || type == 'button' ) {
      addEvent( inputs[i], 'click', exit, false );
      addEvent( inputs[i], 'keypress', linkKeyPress, false );
      }
      }
      }

      function linkKeyPress(e) {
      // check for return key press
      var keyID = (window.event) ? event.keyCode : e.keyCode;
      if (keyID == 13) {
      exit(e);
      }
      }

      function addEvent( thisE, evType, fn, useCapture ) {
      // Updated version which captures passed events
      if (thisE.AddEvent Listener) {
      thisE.AddEventL istener(evType, fn, useCapture);
      return true;
      }
      else if (thisE.attachEv ent) {
      var r = thisE.attachEve nt('on' + evType, fn);
      window.listener s[window.listener s.length] = [ thisE, evType, fn ];
      return r;
      }
      else {
      var xEventFn = thisE['on' + evType];
      if (typeof thisE['on' + evType] != 'function') {
      thisE['on' + evType] = fn;
      }
      else {
      thisE['on' + evType] = function(e) { xEventFn(e); fn(e); };
      }
      }
      }

      function findSourceEleme nt(e) {
      // finds event source
      if (typeof e == 'undefined') {
      var e = window.event;
      }

      var source;
      if (typeof e.target != 'undefined') {
      source = e.target;
      }
      else if (typeof e.srcElement != 'undefined') {
      source = e.srcElement;
      }
      else {
      return true;
      }
      if (source.nodeTyp e == 3) {
      source = source.parentNo de;
      }
      return source;
      }

      function getFormTarget( elt ) {
      // returns the form action attribute from
      // if given the child node of that form
      target = null;
      parentElt = elt.parentNode;
      if( parentElt.nodeT ype == 1 ) {
      if( parentElt.tagNa me == 'FORM' ) {
      target = parentElt.getAt tribute('action ');
      }
      else {
      target = getFormTarget( elt.parentNode );
      }
      }
      else {
      target = getFormTarget( elt.parentNode );
      }
      return target;
      }

      function exit(e) {
      // records click information using ajax
      source = findSourceEleme nt(e);
      tag = source.tagName;
      var id,label,target

      if( tag == 'IMG') {
      if( source.parentNo de.tagName == 'A' ) {
      target = source.parentNo de.href;
      }
      }

      if( tag == 'A' ) {
      target = source.href;
      }

      if( tag == 'INPUT' ) {
      return true;
      if( source.getAttri bute('type') == 'submit' ) {
      target = getFormTarget( source );
      }
      else {
      target = 'script';
      }
      }

      if (window.vapk) {
      xmlHttp=GetXmlH ttpObject();
      if (xmlHttp==null) {
      //alert ("Browser does not support HTTP Request")
      return true;
      }

      var script= "ajax/analytics_exit. php";
      target = escape( target );
      var url=script+"?va pk="+window.vap k+"&exit_page=" +target+"&rand= "+Math.random() ;

      xmlHttp.onready statechange=sta teChanged;
      xmlHttp.open("G ET",url,true) ;
      xmlHttp.send(nu ll);
      }
      return true;
      }

      function entry(ref,uri) {
      //alert("entry running now");
      xmlHttp=GetXmlH ttpObject();
      if (xmlHttp==null) {
      //alert ("Browser does not support HTTP Request")
      return
      }

      var sid= "<?php echo (isset($_COOKIE['PHPSESSID'])) ? $_COOKIE['PHPSESSID'] : NULL; ?>";
      var cid= "<?php echo (isset($_SESSIO N['cid'])) ? $_SESSION['cid'] : 0; ?>";
      var ip= "<?php echo $_SERVER['REMOTE_ADDR']; ?>";
      var res= screen.width + "x" + screen.height;
      var agent= "<?php echo $_SERVER['HTTP_USER_AGEN T']; ?>";
      if (ref==undefined ) {
      ref = 'direct';
      }
      if (uri==undefined ) {
      uri = 'unknown';
      }

      var script= "ajax/analytics_entry .php";

      var url=script+"?ci d="+cid+"&ip="+ ip+"&res="+res+ "&agent="+agent +"&ref="+ref+"& uri="+uri+"&sid ="+sid;

      xmlHttp.onready statechange=sta teChanged;
      xmlHttp.open("G ET",url,true) ;
      xmlHttp.send(nu ll);
      }

      function stateChanged() {
      if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" ) {
      var r=xmlHttp.respo nseText;
      if (!isNaN(r)) {
      window.vapk=r;
      return;
      }
      else if (r.indexOf('htt p://')==0) {
      window.location =r;
      }
      else {
      return;
      }
      }
      }

      function GetXmlHttpObjec t() {
      var xmlHttp=null;
      try { // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest( );
      }
      catch (e) { //Internet Explorer
      try { xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" ); }
      catch (e) { xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP"); }
      }
      return xmlHttp;
      }

      //------------end analytics------------//
      [/code]

      Thanks again!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Can you also post the corresponding HTML?

        Comment

        • henryrhenryr
          New Member
          • Jun 2007
          • 103

          #5
          Hi acoder

          There isn't really any corresponding HTML as such but here is all the information I can think relates to the analytics functions.

          The javascript is loaded by the following:

          [code=html]
          <body onload="load()" >
          [/code]
          [code=javascript]
          //external
          function load() {
          listenAllLinks( );
          }
          [/code]

          The pages contain hundreds of links all in standard format: <a href="..." title="...">... </a>.

          The idea is that the listenAllLinks( ) function adds events to all the anchor elements. When somone clicks on the anchor element, the database is updated with the click recorded.

          I call the entry() function on page load (on an inline script) to record the visit after the page has loaded.

          Hope that gives all the information. I'm a little mystified by the problem, hence asking for help!

          Thanks again!

          Henry

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            So this happens when adding the events, right?

            Check your form ids that they're not reserved words, etc.

            Comment

            • henryrhenryr
              New Member
              • Jun 2007
              • 103

              #7
              after changing
              [code=javascript]
              links= document.getEle mentsByTagName( 'a');
              [/code]
              to
              [code=javascript]
              aLinks= document.getEle mentsByTagName( 'a');
              [/code]

              the script now works! I don't believe it - this bug has been causing me headaches for months.

              Simple is normally the explanation. Thanks for your help acoder!

              Henry

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Glad you got it working.

                Check your code for elements named "links". IE 6 is easily confused!

                Comment

                Working...