Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts

    Stop all Javascript

    How do i stop all href from working in my page with javascript

  • #2
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    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

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    i meen

    How do I use javascript to stop all href links working?

  • #4
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    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.
    Code:
    <!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

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    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

  • #7
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    You can use getAttribute("href") to select the current link, then setAttribute("href", newlink) to set a different one.
    Code:
    <!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

  • Users who have thanked Actinia for this post:

    barkermn01 (12-24-2007)

  • #8
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    o thnks for that you beeen a grate help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •