views:

513

answers:

3

I've searched the internet and this great stackoverflow.com site particularly, but cannot help myself. I am not very experienced programmer and a friend of mine asked me to fix the bug that is on IE6 only. It works on FF, IE7/8, Opera. Here is the PART of the code that gives error message on IE6:

(function(d, n, r) {
  var ie, jscript, settings = {};
  function add(element, type, listener) { element.addEventListener(type, listener, false); };
  function remove(element, type, listener) { element.removeEventListener(type, listener, false); };
  var l = {change:[], ready:[], load:[]};
  a11y = function(f) {
    a11y.change(f);
  };
})
(self.document, self.navigator);

The error is on line 7: a11y.change(f); All other browsers are OK, just IE6. I am not author of the script, just trying to fix this. Can anybody help, please? There must be some problem with function declaration or...?

+1  A: 

The example looks pretty confused there is a lot of code there that looks to be a distraction.

From what I can see the problem is in this code:

a11y = function(f) {
    a11y.change(f);
};

Here you are defining a new function called a11y and inside the definition of that function you are calling a method 'change' on the function a11y being defined. I'm surprised that works in any browser.

Jon Palmer
Thanks you for your comments. I decided to supply the URL of the test page. Here it is: http://www.apbsystems.com/awareness/sco1.html There is a javascript here: http://www.apbsystems.com/awareness/base/js/a11y/a11y.js There are more scripts there but I suppose this is the script that is causing the problem. The error I get is "Object doesn't support this property or method" in IE6. Thank you for all your effort. I am not sure what all the script means. I've spent two days trying to find out. Basicly it opens a window ...
PatrikAPB
+1  A: 

For me it throws an error in IE7 and IE8 as well.

It reports the error line number as line 4 (line 3 in IE6 but IE6 is always off by one). That indicates that the error is in:

function add(element, type, listener) { element.addEventListener(type, listener, false); };  

which isn't surprising since IE doesn't implement addEventListener. The equivalent call on IE is:

element.attachEvent("on" + type, listener)  

It looks like the page is using jQuery, so you should probably use jQuery methods for this.
Instead of calling

add(element, type, listener)  

you could call

$(element).bind(type, listener)

You would also need to fix the "remove" function in line 5.

Sean Hogan
A: 

Hi everybody, thanks for all your help. As suggested by Sean Hogan, the problem was that IE doesn't implement addEventListener. I found similar fix somewhere on the internet and it worked for me.

  /*@cc_on // msie hax
  function add(element, type, listener) { remove(element, type, listener); element.attachEvent("on"+ type, listener); };
  function remove(element, type, listener) { element.detachEvent("on"+ type, listener); };
  settings.jscript = jscript = @_jscript_version;
  settings.ie = ie = parseFloat(n.userAgent.split("MSIE ")[1]);
   if (d && d.execCommand) {
    try { d.execCommand("BackgroundImageCache",false, true); }
    catch (e) { }
  }
 @*/

Thanks again!

patrikAPB