View Full Version : Disabling links partially works
llp00na
04-26-2006, 06:23 PM
dear everyone,
I am trying to disable the links on the following website: www.pcworld.co.uk, but i cant get it quite to work yet.
I am using this code to disable the links.
<script type="text/javascript">
function disableLinks()
{
var items = document.getElementsByTagName("a");
for(var i = 0; i < items.length; i++){
items[i].onclick = function(){
return false;
}
}
}
onload = disableLinks;
</script>
I removed the onload within the body of the html. Once i tested the website, it works fine except for the top menu in whihc the links are not disabled yet. Can someone please help ???
Thanx
Jon Hanlon
04-26-2006, 07:13 PM
I notice that the top menu link tags are a capital A: <A href="...">Whatever</A>
If your document is XHTML or XML it becomes case-sensitive, so I'd try checking for capital A's as well.
function disableLinks() {
var items = document.getElementsByTagName("a");
for (var i = 0; i < items.length; i++) {
items[i].onclick = function() { return false; }
}
var items = document.getElementsByTagName("A");
for (var i = 0; i < items.length; i++) {
items[i].onclick = function() { return false; }
}
}
llp00na
04-27-2006, 07:10 AM
I notice that the top menu link tags are a capital A: <A href="...">Whatever</A>
If your document is XHTML or XML it becomes case-sensitive, so I'd try checking for capital A's as well.
function disableLinks() {
var items = document.getElementsByTagName("a");
for (var i = 0; i < items.length; i++) {
items[i].onclick = function() { return false; }
}
var items = document.getElementsByTagName("A");
for (var i = 0; i < items.length; i++) {
items[i].onclick = function() { return false; }
}
}
I tried your suggestion but it doesnt work.
Any more suggestions ???
This way is a lot better...
Try this:
<a href="javascript: void(0)">Ha ha this link doesn't work!</a>
llp00na
04-27-2006, 02:28 PM
This way is a lot better...
Try this:
<a href="javascript: void(0)">Ha ha this link doesn't work!</a>
your suggestion works only for one link. I however need to disable all links within a web page.
it wont be pleasing going through all links, especially that i have 10 web pages.
:crying: :crying: :crying:
umm...try the for command?
llp00na
04-27-2006, 04:35 PM
umm...try the for command?
Whats that supposed to be ???
Piperwolf
04-27-2006, 04:40 PM
Took me a couple times to read that to figure out what he was talking about. What he should have said was " Try the >for< command", as in a for loop. Do this function a certain amount of times (amount of links on specific site).
llp00na
04-27-2006, 04:57 PM
Took me a couple times to read that to figure out what he was talking about. What he should have said was " Try the >for< command", as in a for loop. Do this function a certain amount of times (amount of links on specific site).
Well thats what i have been trying to do,
<script type="text/javascript">
function disableLinks()
{
var items = document.getElementsByTagName("a");
for(var i = 0; i < items.length; i++){
items[i].onclick = function(){
return false;
}
}
}
onload = disableLinks;
</script>
Piperwolf
04-27-2006, 05:23 PM
I may be grasping at straws here, but on your menu items you end the anchor tag with a capitolized </A>. This *may* be tricking the code into thinking its not an actual <a> or a <A> tag. I paged through a few more pages and it looks like the rest of it does have matching cases, all of it being lower case, just the menu links.
llp00na
04-29-2006, 06:23 PM
I may be grasping at straws here, but on your menu items you end the anchor tag with a capitolized </A>. This *may* be tricking the code into thinking its not an actual <a> or a <A> tag. I paged through a few more pages and it looks like the rest of it does have matching cases, all of it being lower case, just the menu links.
it doesnt seem to be the problem :crying:
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.