disable all href/links when user click a link

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

    disable all href/links when user click a link

    Im trying to prevent the user from clicking any other links on my page when
    the user have selected/clicked a href once.
    Sometimes it takes a while before the next page loads so some user will try
    clicking other links or the same link.
    I can prevent this when i use buttons by calling onclick and in a javascript
    getElementsByTa gName("input") and then check the type to be type of "button"
    or "submit" which i then disable. It works.
    This also works for href html tags by calling onclick and in a javascript
    remove all href, BUT it also stops everything, even the request that is
    about to happen.
    If i use disable getElementsByTa gName("a") on href like with buttons it does
    not get unclickable just get a grey color but you can click on it.

    Any workaround to this? This is a seriuos web app so I want the solution
    where i disable ALL links on my page so it is not possible to click on any
    after the first time.
    All the links is NOT in a form only links using <a href="gosomepla ce"> click
    this link</a> .


  • Lee

    #2
    Re: disable all href/links when user click a link

    KS said:
    [color=blue]
    >Any workaround to this? This is a seriuos web app so I want the solution
    >where i disable ALL links on my page so it is not possible to click on any
    >after the first time.[/color]

    One approach would to ensure that clicking any link immediately loads
    an intermediate page that doesn't have anything to click on.

    Here's an example that builds that intermediate page on the fly.
    This has the side-effect of not allowing some browsers to go BACK
    to the page with the links:


    <html>
    <head>
    <script type="text/javascript">
    function disableOtherLin ks(URL){
    globalHtml="<ht ml><body>Please Wait<script type=\"text/javascript\">"
    +"location=\""+ URL+"\";<\/script></body></html>";
    location="javas cript:window.gl obalHtml";
    }
    </script>
    </head>
    <body>
    <a href="http://www.google.com"
    onclick="disabl eOtherLinks('ht tp://www.google.com' );return false">Google</a>
    <a href="http://www.yahoo.com"
    onclick="disabl eOtherLinks('ht tp://www.yahoo.com') ;return false">Yahoo</a>
    </body>
    </html>

    Comment

    • KS

      #3
      Re: disable all href/links when user click a link

      Good idea if I wanted to display the message over the hole page, but I think
      it is a bit extreme and will be the last choice if nothing else solves this
      problem. There must be someway to disable everything without changing the
      look of the page.
      If youre solution could write out the text but without the href on it i
      would be pleased.
      Something like this before onclick:


      Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

      JavaScript.com is a resource for the JavaScript community. You will find resources and examples for JavaScript beginners as well as support for JavaScript experts. Learn JavaScript or free with our easy to use input output machine.


      and after click , just as above, but then as plain text as if the text was
      writen between <td> ...</td> but without the <a href"blabla"> </a>


      This javascript does the job, but stop the request which is made when i
      click on the link the first time. I would be using onclick to call the
      javascript.

      function disablehref(){

      var input = document.getEle mentsByTagName( "a");

      var count = input.length;


      for(var i =0; i < count; i++){

      document.getEle mentsByTagName( "a")[i].disabled = true;// Does not disable
      the link it just gives it a grey color, but works with buttons

      document.getEle mentsByTagName( "a")[i].removeAttribut e("href"); //OBS this
      works but also stops the request and the next page does not get loaded, just
      hangs in the first page

      document.getEle mentsByTagName( "a")[i].style.cursor=w ait';// just to give the
      mousepointer the wait symbol instead of the hand

      }


      return true;


      }




      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:bl228302rh 6@drn.newsguy.c om...[color=blue]
      > KS said:
      >[color=green]
      > >Any workaround to this? This is a seriuos web app so I want the solution
      > >where i disable ALL links on my page so it is not possible to click on[/color][/color]
      any[color=blue][color=green]
      > >after the first time.[/color]
      >
      > One approach would to ensure that clicking any link immediately loads
      > an intermediate page that doesn't have anything to click on.
      >
      > Here's an example that builds that intermediate page on the fly.
      > This has the side-effect of not allowing some browsers to go BACK
      > to the page with the links:
      >
      >
      > <html>
      > <head>
      > <script type="text/javascript">
      > function disableOtherLin ks(URL){
      > globalHtml="<ht ml><body>Please Wait<script type=\"text/javascript\">"
      > +"location=\""+ URL+"\";<\/script></body></html>";
      > location="javas cript:window.gl obalHtml";
      > }
      > </script>
      > </head>
      > <body>
      > <a href="http://www.google.com"
      > onclick="disabl eOtherLinks('ht tp://www.google.com' );return[/color]
      false">Google</a>[color=blue]
      > <a href="http://www.yahoo.com"
      > onclick="disabl eOtherLinks('ht tp://www.yahoo.com') ;return[/color]
      false">Yahoo</a>[color=blue]
      > </body>
      > </html>
      >[/color]


      Comment

      • VK

        #4
        Re: disable all href/links when user click a link

        1st solution is to work via

        attachEvent / detachEvent with cancelBubble (Explorer)
        addEventListene r / removeEventList ener with useCapture (Netscape)

        "a seriuos web app" - so let it be a serious solution :-)

        But I would propose much easier 2nd solution. Just make a top level event
        listener (window or document) and a hidden div at the bottom of the page

        If this listener gets onclick event and its source is a link, it resizes the
        div to the size of the screen and makes it visible with some good z-index
        (1000 would go for all situations). So effectively you cover all screen with
        a transparent glass - you can see, but you cannot touch.
        If you also make this div to respond on click events (say show an alert
        "Your request is processing, please don't ruch us!" :) - that would be
        totally super.

        KS <nospam@hotmail .com> wrote in message
        news:mI%cb.3297 7$Hb.503617@new s4.e.nsc.no...[color=blue]
        > Im trying to prevent the user from clicking any other links on my page[/color]
        when[color=blue]
        > the user have selected/clicked a href once.
        > Sometimes it takes a while before the next page loads so some user will[/color]
        try[color=blue]
        > clicking other links or the same link.
        > I can prevent this when i use buttons by calling onclick and in a[/color]
        javascript[color=blue]
        > getElementsByTa gName("input") and then check the type to be type of[/color]
        "button"[color=blue]
        > or "submit" which i then disable. It works.
        > This also works for href html tags by calling onclick and in a[/color]
        javascript[color=blue]
        > remove all href, BUT it also stops everything, even the request that is
        > about to happen.
        > If i use disable getElementsByTa gName("a") on href like with buttons it[/color]
        does[color=blue]
        > not get unclickable just get a grey color but you can click on it.
        >
        > Any workaround to this? This is a seriuos web app so I want the solution
        > where i disable ALL links on my page so it is not possible to click on any
        > after the first time.
        > All the links is NOT in a form only links using <a href="gosomepla ce">[/color]
        click[color=blue]
        > this link</a> .
        >
        >[/color]


        Comment

        • Lee

          #5
          Re: disable all href/links when user click a link

          KS said:[color=blue]
          >
          >Good idea if I wanted to display the message over the hole page, but I think
          >it is a bit extreme and will be the last choice if nothing else solves this
          >problem. There must be someway to disable everything without changing the
          >look of the page.[/color]

          Maybe I'm misunderstandin g the situation.
          Once the person has clicked on a link, why do they care
          if the look of the page changes?
          If your page takes long enough to load that they would
          get bored looking at a "Please wait" sort of message,
          maybe you should be concentrating on speeding up the response.

          Comment

          Working...