473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jul 20 '05 #1
2 11100
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Jaeger | last post by:
Dear group, I administrate the web site of a German school (www.gymnasium-burgdorf.de\test.htm) and so far this site has been designed using HTML and CSS only. Due to the increasing number...
1
by: Julius Mong | last post by:
Dear all, according to the ASV3 manual known problem section, to make an <a> execute some Javascript onclick: ...
12
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can...
5
by: Irlan agous | last post by:
I have an echo php link with a javascript mouseout, why doesnt this work? <a href=\"$PHP_SELF?action=list_records&amp;cur_page=$varray&id=$id\" onmouseout=javascript:switchColors(this, 'yellow')>...
9
by: gleverett | last post by:
I have been searching the 'Net, and I can't find the right solution here. I am writing some PHP pages that utilize some Javascript. The script works in Mozilla/Netscape, but fails in IE. I don't...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Spartanicus | last post by:
I'm pondering what the various drawbacks are of the methods to code UI elements who's function relies on javascript and css. Currently on http://www.pan-europe.utvinternet.ie/ I use styled <a>...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
9
by: chrisspencer02 | last post by:
I am looking for a method to extract the links embedded within the Javascript in a web page: an ActiveX component, or example code in C++/Pascal/etc. I am looking for a general solution, not one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.