Javascript Links

C

chris hughes

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
 
L

Lasse Reichstein Nielsen

chris hughes said:
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 #

disable links by removing the a-element:
---
function disableLinks () {
for (var i=0;i < document.links.length;i++) {
var link = document.links;
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.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.href = "";
}
}
document.body.onload=disableLinks;
 
C

chris hughes

Thanks :) :)

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

Thanks again

Lasse Reichstein Nielsen said:
chris hughes said:
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 #

disable links by removing the a-element:
---
function disableLinks () {
for (var i=0;i < document.links.length;i++) {
var link = document.links;
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.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.href = "";
}
}
document.body.onload=disableLinks;
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top