barkermn01
12-20-2007, 09:48 AM
How do i stop all href from working in my page with javascript
|
||||
Stop all Javascriptbarkermn01 12-20-2007, 09:48 AM How do i stop all href from working in my page with javascript Actinia 12-20-2007, 11:39 AM Do you mean: How do I use javascript to stop all href links working? or How do I disable the href="javascript:..." type links? John Rostron barkermn01 12-20-2007, 11:56 PM i meen How do I use javascript to stop all href links working? mikus 12-21-2007, 01:21 AM i don't know why you would want to do that, seems counter-intuitive to me... theres a few ways i can think of going about this, using css is one of them, you could load a style which is like : a{ display:none } and use javascript to apply it you could also add to the href attributes: OnClick="return false;" or even just put a class on the links you want to hide class="hidelink" and then use javascript to select everything that has the class hidelink and add one of the disable methods posted above. Actinia 12-21-2007, 08:17 PM The following simple page has one link that activates the switch-off, and two other links. The stopHref function finds all links <a> and changes the href attribute to #. If you wanted, you could remove the href altogether by substituting 'removeAttribute("href") instead of setAttribute. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function stopHref() { links = document.getElementsByTagName('a'); for (i=0; i < links.length; i++ ) { href = links[i].setAttribute("href", "#"); } return false; } </script> </head> <body> <h4><a href="#" onclick="stopHref();">Click to remove links</a></h4> <h4><a href="http://www.firstlink.org.uk">First link</a></h4> <h4><a href="http://www.secondlink.org.uk">Second link</a></h4> </body> </html> John Rostron barkermn01 12-21-2007, 09:07 PM John Can you rewrite that to make it change the text from (href=") to (href="http://www.barkersmedia.co.uk/get.php?add=)// then the continue the href that why i can bounce them via a server Actinia 12-23-2007, 09:58 AM You can use getAttribute("href") to select the current link, then setAttribute("href", newlink) to set a different one. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function changeLink() { links = document.getElementsByTagName('a'); for (i=0; i < links.length; i++ ) { thisLink = links[i].getAttribute("href"); if (thisLink != "#") { thisLink = "http://www.barkersmedia.co.uk/get.php?add=" + thisLink; links[i].setAttribute("href", thisLink); } } return false; } </script> </head> <body> <h4><a href="#" onclick="changeLink();">Click to remove links</a></h4> <h4><a href="http://www.firstlink.org.uk">First link</a></h4> <h4><a href="http://www.secondlink.org.uk">Second link</a></h4> </body> </html> I have used the fact that the first link has an href of "#" to exclude it. You could target a particular class of links by detecting the class and applying the change just to them. John barkermn01 12-24-2007, 07:24 PM o thnks for that you beeen a grate help |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum