bobzimuta wrote:
<script type="text/javascript">
function disappear(anchor)
{
window.open( anchor.href );
anchor.style.display = 'none';
return false;
}
</script>
Then for every anchor <a href="somepage.html" onclick="return
disappear( this );">click me!</a>
Bonus points if you can get all the anchors to do this when the page
loads WITHOUT adding the onclick to all the links
Perfectly straightforward:
window.onload=function()
{
for(var i=0; i<document.links.length; i++)
document.links[i].onclick=new Function(
"document.links["+i+"].style.display="+
"'none';window.open(document.links["+i+"]);"+
"return false");
}
Setting display to 'none' could upset the layout of the page, so
perhaps visibility='hidden' would be better for this application.
To leave the link visible or re-styled, one can generate a 'clicked'
flag for each link and inspect it before opening the window:
window.onload=function()
{
for(var i=0; i<document.links.length; i++)
document.links[i].onclick=new Function(
"var lnk=document.links["+i+"];"+
"if(typeof lnk.wasClicked=='undefined')"+
"{window.open(lnk);lnk.style.visibility="+
"'hidden';lnk.wasClicked=true;}return false;");
}
--
S.C.