J
Jamie Jackson
I'm rewriting all links' onclick events, but I'm having a problem. The
onclick event that I'm inserting works correctly in Opera, but not in
FF or IE.
I'm retroactively adding the statement "return promptBeforeOpening();"
[promptBeforeOpening() is my own custom method.]
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();
Opera seems to do me a favor, and makes it work for me:
(Before Rewriting)
onClick:undefined
(After Rewriting)
onClick:function anonymous(event) {return promptBeforeOpening();}
^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
See how Opera adds that weird method definition? Whatever that is, it
works.
So, the question is, what do I need to do to get it to work in the
other browsers?
Thanks,
Jamie
<a href="http://www.adcouncil.org/campaigns/adoption/" target="new">my
link</a>
<script type="text/javascript">
function promptBeforeOpening () {
if (confirm("LEAVING SITE X\n\nYou are about to leave site x to go
to another location that is not maintained by x. X takes no
responsibility for and exercises no control over the views that may be
represented, or the accuracy, privacy policies, copyright or trademark
compliance, or the legality of any material contained on external
sites. \n\nTo proceed to the Web site, please select the OK
button.")) {
// confirmed: thank you, drive through
return true;
} else {
// user has cancelled, don't go to link
return false;
}
}
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.onclick + " Href:" + document.links.href +
"</h4>");
origOnClick = document.links.onclick;
// rewrite the link's onClick to prompt before going
document.links.onclick = "return promptBeforeOpening();";
if (origOnClick != null) {
// old onClick exists, so append it to the new one
document.links.onclick += origOnClick;
}
// debug output
document.write("<h4 style='color: blue'>(After) onClick:" +
document.links.onclick + " Href:" + document.links.href +
"</h4>");
}
</script>
onclick event that I'm inserting works correctly in Opera, but not in
FF or IE.
I'm retroactively adding the statement "return promptBeforeOpening();"
[promptBeforeOpening() is my own custom method.]
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();
Opera seems to do me a favor, and makes it work for me:
(Before Rewriting)
onClick:undefined
(After Rewriting)
onClick:function anonymous(event) {return promptBeforeOpening();}
^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
See how Opera adds that weird method definition? Whatever that is, it
works.
So, the question is, what do I need to do to get it to work in the
other browsers?
Thanks,
Jamie
<a href="http://www.adcouncil.org/campaigns/adoption/" target="new">my
link</a>
<script type="text/javascript">
function promptBeforeOpening () {
if (confirm("LEAVING SITE X\n\nYou are about to leave site x to go
to another location that is not maintained by x. X takes no
responsibility for and exercises no control over the views that may be
represented, or the accuracy, privacy policies, copyright or trademark
compliance, or the legality of any material contained on external
sites. \n\nTo proceed to the Web site, please select the OK
button.")) {
// confirmed: thank you, drive through
return true;
} else {
// user has cancelled, don't go to link
return false;
}
}
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.onclick + " Href:" + document.links.href +
"</h4>");
origOnClick = document.links.onclick;
// rewrite the link's onClick to prompt before going
document.links.onclick = "return promptBeforeOpening();";
if (origOnClick != null) {
// old onClick exists, so append it to the new one
document.links.onclick += origOnClick;
}
// debug output
document.write("<h4 style='color: blue'>(After) onClick:" +
document.links.onclick + " Href:" + document.links.href +
"</h4>");
}
</script>