views:

494

answers:

1

I'm using the following code to override a JavaScript function named dismissRelatedLookupPopup(). In Firefox, this works without a problem (displays the alert once and runs my code), but in Internet Explorer 7 it results in an infinite loop displaying the alert() forever. I'm doing this because I don't control the code where dismissRelatedLookupPopup() is called, and I'd like to add a hook of my own when it's called. Is there a cross-browser way to do this?

old_dismissRelatedLookupPopup = dismissRelatedLookupPopup;
dismissRelatedLookupPopup = function dismissRelatedLookupPopup(win, chosenId) {
    alert("i hate ie");
    old_dismissRelatedLookupPopup(win,chosenId);
    var name = windowname_to_id(win.name);
    var elem = document.getElementById(name);
    elem.onchange();
}

Note: It's my understanding that when JavaScript updates the value of an element directly (ie. elem.value = 1) that the onchange() event of that element will not fire. That is why I'm including this code to force the onchange() when the value is updated.

+3  A: 

I'm pretty sure that changing this line:

dismissRelatedLookupPopup = function dismissRelatedLookupPopup(win, chosenId)

to

dismissRelatedLookupPopup = function (win, chosenId)

will cure what ails ya.

Triptych
Bingo! Thanks a bunch. After you pointed it out, it's pretty obvious. I even wonder why Firefox was accepting this code...
I'm not even sure it's invalid code. Just kinda weird.
Triptych