Make hyperlink invisible?

B

Benton

Hi there,

I would like to make an hyperlink invisible, or disabled, with a click. The
hyperlink opens a new window (target = _blank) and once the new window is
shown, I don't want the hyperlink to be active anymore.

How can I do this?

Thanks in advance,

-Benton
 
B

bobzimuta

<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
 
R

Randy Webb

bobzimuta said the following on 3/31/2006 9:00 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<script type="text/javascript">
function disappear(anchor)
{
window.open( anchor.href );

And if the user is using a popup blocker that disables window.open?
Symantec comes to mind first.
anchor.style.display = 'none';
return false;
}
</script>

Then for every anchor <a href="somepage.html" onclick="return
disappear( this );">click me!</a>

<a href="somepage.html" onclick="this.style.display = 'none';">Look Ma!
No function said:
Bonus points if you can get all the anchors to do this when the page
loads WITHOUT adding the onclick to all the links

Triple bonus points to you if you can learn to quote and post properly.
 
S

Stephen Chalmers

bobzimuta said:
<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.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.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;");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top