Javascript Links

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris hughes

    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


  • Lasse Reichstein Nielsen

    #2
    Re: Javascript Links

    "chris hughes" <chris(remove)_ hughes4@hotmail .com> writes:
    [color=blue]
    > 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 #[/color]

    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.chil dNodes.length;j ++) {
    link.parentNode .insertBefore(l ink.firstChild, link);
    }
    link.parentNode .removeChild(li nk);
    }
    }
    document.body.o nload=disableLi nks;
    ---


    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.o nload=disableLi nks;
    ---
    (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.o nload=disableLi nks;
    ---

    Good luck with whatever you are up to.
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • chris hughes

      #3
      Re: Javascript Links

      Thanks :) :)

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

      Thanks again

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:vfu3xknb.f sf@hotpop.com.. .[color=blue]
      > "chris hughes" <chris(remove)_ hughes4@hotmail .com> writes:
      >[color=green]
      > > Can anyone please tell me how to create a javascript that I can place in[/color][/color]
      any[color=blue][color=green]
      > > page that will disable all the links or just change all the hrefs to #[/color]
      >
      > 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.chil dNodes.length;j ++) {
      > link.parentNode .insertBefore(l ink.firstChild, link);
      > }
      > link.parentNode .removeChild(li nk);
      > }
      > }
      > document.body.o nload=disableLi nks;
      > ---
      >
      >
      > 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.o nload=disableLi nks;
      > ---
      > (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.o nload=disableLi nks;
      > ---
      >
      > Good luck with whatever you are up to.
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      > 'Faith without judgement merely degrades the spirit divine.'[/color]


      Comment

      Working...