JavaScript click event processing to get URL of link that was clicked?

Discussion in 'JavaScript' started by Webed4it, Mar 27, 2010.

  1. #1
    If you register a click listener something like this:

    <script type="text/javascript">
    
    Event.observe(document.body, 'click', function(event) {
    
    if( the url that was clicked == xxx){
    alert('hi');
    }
    
    });
    </script>
    Code (markup):
    how do you get the destination URL of the link that was clicked, assuming it was a link.
     
    Webed4it, Mar 27, 2010 IP
  2. inegoita

    inegoita Member

    Messages:
    54
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Hi

    i'm not familiar to the framework you are using (I guess it's the Prototype)
    from what I can figure out from their documentation you need to do something like this:

    <script type="text/javascript">

    Event.observe(document.body, 'click', function(event) {

    if( event.findElement().href == 'xxx'){
    alert('hi');
    }

    });
    </script>

    event.findElement() should return the element you clicked on, and href should contain the link


    hope it helps
    John
     
    inegoita, Mar 28, 2010 IP