disable all href/links when user click a link

Discussion in 'Javascript' started by Lee, Sep 26, 2003.

  1. Lee

    Lee Guest

    KS said:

    >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.


    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 disableOtherLinks(URL){
    globalHtml="<html><body>Please Wait<script type=\"text/javascript\">"
    +"location=\""+URL+"\";<\/script></body></html>";
    location="javascript:window.globalHtml";
    }
    </script>
    </head>
    <body>
    <a href="http://www.google.com"
    onclick="disableOtherLinks('http://www.google.com');return false">Google</a>
    <a href="http://www.yahoo.com"
    onclick="disableOtherLinks('http://www.yahoo.com');return false">Yahoo</a>
    </body>
    </html>
     
    Lee, Sep 26, 2003
    #1
    1. Advertising

  2. Lee

    KS Guest

    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
    getElementsByTagName("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 getElementsByTagName("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="gosomeplace"> click
    this link</a> .
     
    KS, Sep 26, 2003
    #2
    1. Advertising

  3. Lee

    KS Guest

    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:

    www.google.com
    www.onjava.com
    www.javascript.com

    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.getElementsByTagName("a");

    var count = input.length;


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

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

    document.getElementsByTagName("a").removeAttribute("href"); //OBS this
    works but also stops the request and the next page does not get loaded, just
    hangs in the first page

    document.getElementsByTagName("a").style.cursor=wait';// just to give the
    mousepointer the wait symbol instead of the hand

    }


    return true;


    }




    "Lee" <> wrote in message
    news:...
    > KS said:
    >
    > >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.

    >
    > 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 disableOtherLinks(URL){
    > globalHtml="<html><body>Please Wait<script type=\"text/javascript\">"
    > +"location=\""+URL+"\";<\/script></body></html>";
    > location="javascript:window.globalHtml";
    > }
    > </script>
    > </head>
    > <body>
    > <a href="http://www.google.com"
    > onclick="disableOtherLinks('http://www.google.com');return

    false">Google</a>
    > <a href="http://www.yahoo.com"
    > onclick="disableOtherLinks('http://www.yahoo.com');return

    false">Yahoo</a>
    > </body>
    > </html>
    >
     
    KS, Sep 26, 2003
    #3
  4. Lee

    VK Guest

    1st solution is to work via

    attachEvent / detachEvent with cancelBubble (Explorer)
    addEventListener / removeEventListener 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 <> wrote in message
    news:mI%cb.32977$...
    > 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
    > getElementsByTagName("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 getElementsByTagName("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="gosomeplace">

    click
    > this link</a> .
    >
    >
     
    VK, Sep 26, 2003
    #4
  5. Lee

    Lee Guest

    KS said:
    >
    >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.


    Maybe I'm misunderstanding 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.
     
    Lee, Sep 27, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    203,032
    Adrienne Boswell
    Jun 20, 2006
  2. Sita Rami Reddy
    Replies:
    2
    Views:
    94
    Sita Rami Reddy
    Nov 12, 2008
  3. Soren Vejrum
    Replies:
    4
    Views:
    686
    Lasse Reichstein Nielsen
    Jul 5, 2003
  4. JN
    Replies:
    3
    Views:
    142
    Thomas 'PointedEars' Lahn
    Apr 8, 2004
  5. Jamie Jackson

    Disable Link from HREF Attribute?

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    4
    Views:
    240
    Jamie Jackson
    Oct 25, 2004
Loading...

Share This Page