henryhenry Posted November 8, 2007 Share Posted November 8, 2007 Hi AllI'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: links = document.getElementsByTagName('a'); 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 Link to comment Share on other sites More sharing options...
Reg Edit Posted November 8, 2007 Share Posted November 8, 2007 What IE? It works fine for me in IE6 and IE7. Link to comment Share on other sites More sharing options...
aspnetguy Posted November 8, 2007 Share Posted November 8, 2007 please post your full code. That state does indeed work in IE6 and 7 so it is probly a syntax error or something in your code causing the problem. Link to comment Share on other sites More sharing options...
henryhenry Posted November 8, 2007 Author Share Posted November 8, 2007 please post your full code. That state does indeed work in IE6 and 7 so it is probly a syntax error or something in your code causing the problem.Hi OK. Here's all the functions for my analytics. I have used snippets from various locations to put it together. Please note I use PHP to generate the js file hence the small amounts of <?php ?>. Thanks for your help!//-------------------ANALYTICS--------------------------//var xmlHttp; //ajax objectvar vapk; //the visitor pk which is retrieved on entry and used on exit to updatevar listeners = []; //arrayfunction listenAllLinks() { if (!document.getElementsByTagName) return false; // find links in document aLinks = document.getElementsByTagName('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.getElementsByTagName('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.AddEventListener) { thisE.AddEventListener(evType, fn, useCapture); return true; } else if (thisE.attachEvent) { var r = thisE.attachEvent('on' + evType, fn); window.listeners[window.listeners.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 findSourceElement(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.nodeType == 3) { source = source.parentNode; } 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.nodeType == 1 ) { if( parentElt.tagName == 'FORM' ) { target = parentElt.getAttribute('action'); } else { target = getFormTarget( elt.parentNode ); } } else { target = getFormTarget( elt.parentNode ); } return target;}function exit(e) { // records click information using ajax source = findSourceElement(e); tag = source.tagName; var id,label,target if( tag == 'IMG') { if( source.parentNode.tagName == 'A' ) { target = source.parentNode.href; } } if( tag == 'A' ) { target = source.href; } if( tag == 'INPUT' ) { return true; if( source.getAttribute('type') == 'submit' ) { target = getFormTarget( source ); } else { target = 'script'; } } if (window.vapk) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { //alert ("Browser does not support HTTP Request") return true; } var script= "ajax/analytics_exit.php"; target = escape( target ); var url=script+"?vapk="+window.vapk+"&exit_page="+target+"&rand="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } return true;}function entry(ref,uri) { //alert("entry running now"); xmlHttp=GetXmlHttpObject(); 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($_SESSION['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_AGENT']; ?>"; if (ref==undefined) { ref = 'direct'; } if (uri==undefined) { uri = 'unknown'; } var script= "ajax/analytics_entry.php"; var url=script+"?cid="+cid+"&ip="+ip+"&res="+res+"&agent="+agent+"&ref="+ref+"&uri="+uri+"&sid="+sid; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null);}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { var r=xmlHttp.responseText; if (!isNaN(r)) { window.vapk=r; return; } else if (r.indexOf('http://')==0) { window.location=r; } else { return; } }}function GetXmlHttpObject() { 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.XMLHTTP"); } } return xmlHttp;}//------------end analytics------------// Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.