473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IE6 specific Object Doesn't Support ... Error

103 100+
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:

Expand|Select|Wrap|Line Numbers
  1. links = document.getElementsByTagName('a');
  2.  
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
Nov 8 '07 #1
7 3305
acoder
16,027 Expert Mod 8TB
That line shouldn't cause errors. Can you post the rest of your code?
Nov 8 '07 #2
henryrhenryr
103 100+
Hi

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

Expand|Select|Wrap|Line Numbers
  1. /-------------------ANALYTICS--------------------------//
  2. var xmlHttp; //ajax object
  3. var vapk; //the visitor pk which is retrieved on entry and used on exit to update
  4. var listeners = []; //array
  5.  
  6. function listenAllLinks() {
  7.   if (!document.getElementsByTagName) return false;
  8.   // find links in document
  9.   aLinks = document.getElementsByTagName('a');
  10.  
  11.   // if link does have a id add one
  12.   for (var i = 0; i < aLinks.length; i++) {
  13.     addEvent( aLinks[i], 'click', exit, false );
  14.     addEvent( aLinks[i], 'keypress', linkKeyPress, false );
  15.   }
  16.  
  17.   // find buttons in document
  18.   inputs = document.getElementsByTagName('input');
  19.   for (var i = 0; i < inputs.length; i++) {
  20.     type = inputs[i].getAttribute('type');
  21.     // only attach events to buttons
  22.     if ( type == 'submit' || type == 'button' ) {
  23.       addEvent( inputs[i], 'click', exit, false );
  24.       addEvent( inputs[i], 'keypress', linkKeyPress, false );
  25.     }
  26.   }
  27. }
  28.  
  29. function linkKeyPress(e) {
  30.   // check for return key press
  31.   var keyID = (window.event) ? event.keyCode : e.keyCode;
  32.   if (keyID == 13) {
  33.     exit(e);
  34.   }
  35. }
  36.  
  37. function addEvent( thisE, evType, fn, useCapture ) {
  38.   // Updated version which captures passed events
  39.   if (thisE.AddEventListener) {
  40.     thisE.AddEventListener(evType, fn, useCapture);
  41.     return true;
  42.   }
  43.   else if (thisE.attachEvent) {
  44.     var r = thisE.attachEvent('on' + evType, fn);
  45.     window.listeners[window.listeners.length] = [ thisE, evType, fn ];
  46.     return r;
  47.   }
  48.   else {
  49.     var xEventFn = thisE['on' + evType];
  50.     if (typeof thisE['on' + evType] != 'function')    {
  51.       thisE['on' + evType] = fn;
  52.     }
  53.     else {
  54.       thisE['on' + evType] = function(e) { xEventFn(e); fn(e); };
  55.     }
  56.   }
  57. }
  58.  
  59. function findSourceElement(e) {
  60.   // finds event source
  61.   if (typeof e == 'undefined') {
  62.     var e = window.event;
  63.   }
  64.  
  65.   var source;
  66.   if (typeof e.target != 'undefined') {
  67.     source = e.target;
  68.   }
  69.   else if (typeof e.srcElement != 'undefined') {
  70.     source = e.srcElement;
  71.   }
  72.   else {
  73.     return true;
  74.   }
  75.   if (source.nodeType == 3) {
  76.     source = source.parentNode;
  77.   }
  78.   return source;
  79. }
  80.  
  81. function getFormTarget( elt ) {
  82.   // returns the form action attribute from
  83.   // if given the child node of that form
  84.   target = null;
  85.   parentElt = elt.parentNode;
  86.   if( parentElt.nodeType == 1 ) {
  87.     if( parentElt.tagName == 'FORM' ) {
  88.       target = parentElt.getAttribute('action');
  89.     }
  90.     else {
  91.       target = getFormTarget( elt.parentNode );
  92.     }
  93.   }
  94.   else {
  95.     target = getFormTarget( elt.parentNode );
  96.   }
  97.   return target;
  98. }
  99.  
  100. function exit(e) {
  101.   // records click information using ajax
  102.   source = findSourceElement(e);
  103.   tag = source.tagName;
  104.   var id,label,target
  105.  
  106.   if( tag == 'IMG') {
  107.     if( source.parentNode.tagName == 'A' ) {
  108.       target = source.parentNode.href;
  109.     }
  110.   }
  111.  
  112.   if( tag == 'A' ) {
  113.     target = source.href;
  114.   }
  115.  
  116.   if( tag == 'INPUT' ) {
  117.     return true;
  118.     if( source.getAttribute('type') == 'submit' ) {
  119.       target = getFormTarget( source );
  120.     }
  121.     else {
  122.       target = 'script';
  123.     }
  124.   }
  125.  
  126.   if (window.vapk) {
  127.     xmlHttp=GetXmlHttpObject();
  128.     if (xmlHttp==null) {
  129.       //alert ("Browser does not support HTTP Request")
  130.       return true;
  131.     }
  132.  
  133.     var script= "ajax/analytics_exit.php";
  134.     target = escape( target );
  135.     var url=script+"?vapk="+window.vapk+"&exit_page="+target+"&rand="+Math.random();
  136.  
  137.     xmlHttp.onreadystatechange=stateChanged;
  138.     xmlHttp.open("GET",url,true);
  139.     xmlHttp.send(null);
  140.   }
  141.   return true;
  142. }
  143.  
  144. function entry(ref,uri) {
  145.   //alert("entry running now");
  146.   xmlHttp=GetXmlHttpObject();
  147.   if (xmlHttp==null) {
  148.     //alert ("Browser does not support HTTP Request")
  149.     return
  150.   }
  151.  
  152.   var sid= "<?php echo (isset($_COOKIE['PHPSESSID'])) ? $_COOKIE['PHPSESSID'] : NULL; ?>";
  153.   var cid= "<?php echo (isset($_SESSION['cid'])) ? $_SESSION['cid'] : 0; ?>";
  154.   var ip= "<?php echo $_SERVER['REMOTE_ADDR']; ?>";
  155.   var res= screen.width + "x" + screen.height;
  156.   var agent= "<?php echo $_SERVER['HTTP_USER_AGENT']; ?>";
  157.   if (ref==undefined) {
  158.     ref = 'direct';
  159.   }
  160.   if (uri==undefined) {
  161.     uri = 'unknown';
  162.   }
  163.  
  164.   var script= "ajax/analytics_entry.php";
  165.  
  166.   var url=script+"?cid="+cid+"&ip="+ip+"&res="+res+"&agent="+agent+"&ref="+ref+"&uri="+uri+"&sid="+sid;
  167.  
  168.   xmlHttp.onreadystatechange=stateChanged;
  169.   xmlHttp.open("GET",url,true);
  170.   xmlHttp.send(null);
  171. }
  172.  
  173. function stateChanged() {
  174.   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
  175.     var r=xmlHttp.responseText;
  176.     if (!isNaN(r)) {
  177.       window.vapk=r;
  178.       return;
  179.     }
  180.     else if (r.indexOf('http://')==0) {
  181.       window.location=r;
  182.     }
  183.     else {
  184.       return;
  185.     }
  186.   }
  187. }
  188.  
  189. function GetXmlHttpObject() {
  190.   var xmlHttp=null;
  191.   try { // Firefox, Opera 8.0+, Safari
  192.     xmlHttp=new XMLHttpRequest();
  193.   }
  194.   catch (e) { //Internet Explorer
  195.     try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  196.     catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  197.   }
  198.   return xmlHttp;
  199. }
  200.  
  201. //------------end analytics------------//
  202.  
Thanks again!
Nov 9 '07 #3
acoder
16,027 Expert Mod 8TB
Can you also post the corresponding HTML?
Nov 9 '07 #4
henryrhenryr
103 100+
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:

Expand|Select|Wrap|Line Numbers
  1. <body onload="load()">
  2.  
Expand|Select|Wrap|Line Numbers
  1. //external
  2. function load() {
  3.   listenAllLinks();
  4. }
  5.  
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
Nov 9 '07 #5
acoder
16,027 Expert Mod 8TB
So this happens when adding the events, right?

Check your form ids that they're not reserved words, etc.
Nov 9 '07 #6
henryrhenryr
103 100+
after changing
Expand|Select|Wrap|Line Numbers
  1. links= document.getElementsByTagName('a');
  2.  
to
Expand|Select|Wrap|Line Numbers
  1. aLinks= document.getElementsByTagName('a');
  2.  
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
Nov 9 '07 #7
acoder
16,027 Expert Mod 8TB
Glad you got it working.

Check your code for elements named "links". IE 6 is easily confused!
Nov 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Matt | last post by:
I tried to display all html control types in the form. But it has run time error "object doesn't support this property or method" on document.write(obj.type); Even I do document.write('hello...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
0
by: Roman | last post by:
I'm trying to create the form which would allow data entry to the Client table, as well as modification and deletion of existing data rows. For some reason the DataGrid part of functionality stops...
0
by: fniles | last post by:
I created a CAB file for a 3rd party control (StockChartX) it using CABARC.exe that comes from Microsoft SDK. In the CAB file I included the StockChartX.ocx and StockChartX.INF. Then, I signed the...
5
by: John Olbert | last post by:
Subject: Error is Object doesn't support this property or method I am trying to pass a C# string under Vs2005 (Net2) to an Vb6 ActiveX Control. I get the following runtime error-- "Object...
4
by: Jason Richmeier | last post by:
I am sure this has been asked at least once before but I could not find anything when searching. If I set the value of the ExitCode property to 1066 for a windows service, the text "A service...
8
by: Kevin Blount | last post by:
I'm tyring to access an object created by using a method from a third party API. The documentation tells me what object should be return, and the properties of that object, but when I try and...
11
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Has anybody worked with performancecounter object to access counters on remote machine? I managed to write code that retrieves counters categories froma remote machine, when I try another remote...
4
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.