Connecting Tech Pros Worldwide Help | Site Map

Javascript Links

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 09:09 AM
chris hughes
Guest
 
Posts: n/a
Default Javascript Links

Can anyone please tell me how to create a javascript that I can place in any
page that will disable all the links or just change all the hrefs to #

Many Thanks

Chris Hughes



  #2  
Old July 20th, 2005, 09:09 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: Javascript Links

"chris hughes" <chris(remove)_hughes4@hotmail.com> writes:
[color=blue]
> Can anyone please tell me how to create a javascript that I can place in any
> page that will disable all the links or just change all the hrefs to #[/color]

disable links by removing the a-element:
---
function disableLinks () {
for (var i=0;i < document.links.length;i++) {
var link = document.links[i];
for (var j=0;j<link.childNodes.length;j++) {
link.parentNode.insertBefore(link.firstChild,link) ;
}
link.parentNode.removeChild(link);
}
}
document.body.onload=disableLinks;
---


Disable links by adding javascript clickhandler:
---
function retFalse () {
return false;
}
function disableLinks () {
for (var i=0;i < document.links.length;i++) {
document.links[i].onclick = retFalse;
}
}
document.body.onload=disableLinks;
---
(the disabling only works with javascript on, but so does this
script to begin with)

Change all hrefs to "" (shorter than "#"):
---
function disableLinks () {
for (var i=0;i < document.links.length;i++) {
document.links[i].href = "";
}
}
document.body.onload=disableLinks;
---

Good luck with whatever you are up to.
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
  #3  
Old July 20th, 2005, 09:09 AM
chris hughes
Guest
 
Posts: n/a
Default Re: Javascript Links

Thanks :) :)

Just out of interest is there anyway to disable all links and active a
specific one?

Thanks again

"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
news:vfu3xknb.fsf@hotpop.com...[color=blue]
> "chris hughes" <chris(remove)_hughes4@hotmail.com> writes:
>[color=green]
> > Can anyone please tell me how to create a javascript that I can place in[/color][/color]
any[color=blue][color=green]
> > page that will disable all the links or just change all the hrefs to #[/color]
>
> disable links by removing the a-element:
> ---
> function disableLinks () {
> for (var i=0;i < document.links.length;i++) {
> var link = document.links[i];
> for (var j=0;j<link.childNodes.length;j++) {
> link.parentNode.insertBefore(link.firstChild,link) ;
> }
> link.parentNode.removeChild(link);
> }
> }
> document.body.onload=disableLinks;
> ---
>
>
> Disable links by adding javascript clickhandler:
> ---
> function retFalse () {
> return false;
> }
> function disableLinks () {
> for (var i=0;i < document.links.length;i++) {
> document.links[i].onclick = retFalse;
> }
> }
> document.body.onload=disableLinks;
> ---
> (the disabling only works with javascript on, but so does this
> script to begin with)
>
> Change all hrefs to "" (shorter than "#"):
> ---
> function disableLinks () {
> for (var i=0;i < document.links.length;i++) {
> document.links[i].href = "";
> }
> }
> document.body.onload=disableLinks;
> ---
>
> Good luck with whatever you are up to.
> /L
> --
> Lasse Reichstein Nielsen - lrn@hotpop.com
> Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
> 'Faith without judgement merely degrades the spirit divine.'[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.