Connecting Tech Pros Worldwide Help | Site Map

Javascript Links

  #1  
Old July 20th, 2005, 10:09 AM
chris hughes
Guest
 
Posts: n/a
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, 10:09 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

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, 10:09 AM
chris hughes
Guest
 
Posts: n/a

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]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with javascript links ArcInversion answers 1 May 22nd, 2006 12:47 PM
Unable to Drag Javascript Links David McCulloch answers 2 July 23rd, 2005 05:37 PM
Javascript links and search engine spiders Simon Wigzell answers 5 July 20th, 2005 12:07 PM