Opened 13 years ago

Closed 12 years ago

#1592 closed defect (wontfix)

around advice on getElementById fails on IE

Reported by: guest Owned by: alex
Priority: high Milestone: 0.9
Component: Events Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

Hi all,

I'm trying to override the getElementById to change the id which is passed to it. (append some dynamic stuff to it).

This works great with the around advice functionality, but only on Firefox and Opera 9. On IE (IE7RC1 or IE6) it fails.

Here is my code:

<script language="JavaScript" type="text/javascript"> <!--
function myGetElementByID(invocation) {
  var id = invocation.args[0];
  
  if (id.indexOf("-1_VALUE") != -1) {
    return invocation.proceed();
  }
  if (id.indexOf("_VALUE") != -1) {
    id = id.substring(0, id.indexOf("_VALUE"));
    
  }
  invocation.args[0] = id + "_-1_VALUE";
  try {
    var result =  invocation.proceed();
  }
  catch (e) {
    alert(e + "");
  }  
  return result;
}
//-->
</script>

<script type="text/javascript"> <!--
function init() {
  dojo.event.connect("around", document, "getElementById", this, "myGetElementByID");
}

//dojo.addOnLoad(init); // launch init() function
window.onload=new Function('init();');
//-->
</script>

IE fails on the line var result = invocation.proceed();

document.getElementById(...) is null or not an object.

Does anyone has an idea how to solve this issue ? (if it solvable :))

Wim

Change History (4)

comment:1 Changed 13 years ago by guest

The try-catch part I copy-pasted is wrong:

It should simply be:

return result =  invocation.proceed();

instead of

try {
    var result =  invocation.proceed();
  }
  catch (e) {
    alert(e + "");
  }  
  return result;

comment:2 Changed 13 years ago by guest

I meant:

return invocation.proceed();

but I guess you all know that I meant this :-)

comment:3 Changed 13 years ago by dylan

Milestone: 0.5
Priority: highnormal
severity: criticalmajor

comment:4 Changed 12 years ago by alex

Resolution: wontfix
Status: newclosed

unfortunantly, this isn't something we can fix. It's due to the COM-bound nature of the Document object on IE. You *can* add around advice to dojo.byId(), which is the method you should be using anyway for other reasons. Marking "wontfix".

Note: See TracTickets for help on using tickets.