SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prevent Default Problem

    Hello. In my code I assign an event listener to an anchor link and then prevent the default action with event.preventDefault() method. Then after some code execution program needs default anchor actions back. Although I use removeEventListener default actions doesnt appear to be working. How can I call back default actions again?
    Thanks in advance.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Once you've prevented a certain event you can't enable it again.

    How are you assigning and removing the event listener?

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would suggest that you prevent default action based on a condition. This way you don't have to worry about enabling it back again and the default action will be prevented when the condition meets.

    For example:
    Code JavaScript:
    if(condition)
    {
          if(event.preventDefault)
                 event.preventDefault() //for gecko browsers
          else
                 event.returnValue = false // for IE
    }
    else
         //do nothing. this will continue with default action
    With Regards
    Pman
    http://www.pmansLab.com


Bookmarks

Posting Permissions

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