SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast indepthmedia's Avatar
    Join Date
    Apr 2005
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add a "piggyback" event to an existing onClick of an image

    I have an image that already has an onClick event (a simple window.print(); command). I am trying to figure out how I can add another function to this onClick so when a user clicks this button not only will the print window appear but another js function will also fire off. How do I accomplish this? Unfortunately I am not able to simply manually add the function to the onClick so is there a way to listen for all "window.print();" events and send a second event (my js function) at that time?

    Thanks!!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, but you can listen for all click events on that element. Get rid of the inline onclick (it's not onClick by the way) event handler and use this:

    Code javascript:
    document.getElementById('the_image').onclick = function() {
      window.print();
      doOtherStuff();
    }


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
  •