FF and IE rewrite it as I would expect them to, but it turns out that
that doesn't work (no disclaimer pops up, and the link is not
disabled):
(Before Rewriting)
onClick:undefined
(After Rewriting)
onClick:return promptBeforeOpening();

for (var i=0; i < document.links.length; i++) { // save a copy of any onClick that the link may have originally had // debug output document.write("<h4 style='color: blue'>(Before) onClick:" + document.links[i].onclick + " Href:" + document.links[i].href + "</h4>"); origOnClick = document.links[i].onclick; // rewrite the link's onClick to prompt before going document.links[i].onclick = "return promptBeforeOpening();";
The onclick property is usually a function object and not a string (test
typeof origOnClick to check that), thus if you want to assign a
different event handler you need to assign a function. There are
different ways to construct one, you can use a function expresssion:
document.links[i].onclick = function (evt) {
return promptBeforeOpening();
};
or you can use the Function constructor to create a function
document.links[i].onclick = new Function("evt",
"return promptBeforeOpening();"
);
or you can declare a gobal function
function newClickHandler (evt) {
return promptBeforeOpening();
}
and assign it
document.links[i].onclick = newClickHandler;
if (origOnClick != null) { // old onClick exists, so append it to the new one document.links[i].onclick += origOnClick;

Again string operation doesn't help, what could help is
var link = document.links[i];
link.originalOnclick = link.onclick;
link.onclick = function (evt) {
if (this.originalOnclick) {
this.originalOnclick(evt);
}
return promptBeforeOpening();
};
but depending on what browsers you target you could avoid scripting
onclick as a property and instead use attachEventListener (W3C DOM in
Mozilla, Netscape 6/7, Opera 7) or attachEvent (MSIE 5.5/6 DOM) to add
an additional event handler as needed.

So, the question is, what do I need to do to get it to work in the other browsers?

document.links[i].onclick is a reference to the function that handles the
-onclick- event, not a string containing the JavaScript within that
function. So you assign the reference of the function you want to assign
to the -onclick- event: