By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,638 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,638 IT Pros & Developers. It's quick & easy.

Javascript Links

P: 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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"chris hughes" <chris(remove)_h******@hotmail.com> writes:
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[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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Thanks :) :)

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

Thanks again

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:vf**********@hotpop.com...
"chris hughes" <chris(remove)_h******@hotmail.com> writes:
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[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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.