"Frank" wrote
I have an onunload event in the body tag. When it is activated I want to
know if a <a></a> href was clicked and which one. Is there some document
property or any other object available for such a thing?
No, thanks, I don't want to use the onclick or any other event on the <a>
tag.
document.body.onunload=function(){
if( document.activeElement &&
document.activeElement.tagName &&
document.activeElement.tagName.toLowerCase()=='a' )
alert(document.activeElement.href);
}
This will not work in every browser, and it will work incorrectly if user
focuses an <a> then changes his mind and types a new url in the address bar,
since the link will be the active element, but not the reason for the
unload.
Perhaps a better approach is to put an onclick handler on every <a> after
all.
This isn't too difficult however, with a loop through all links onload:
for(var
i=0;i<document.links.length;i++)document.links[i].onclick=somefunction;
HTH
Ivo