SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    event handling in javascript

    I have a text link on which i want the right click calls the same javascript function as left click. Can this be implemented both in IE and Netscape?

    Basically i dont't want the right click on this link showing up the context sensitive menu with open in new window and save target as options as when selected one of these, open in new window will result in page not found and save target as will result in client side run time error.

    I also don't want to disable the right mose click on the page which i can do through the following:

    document.oncontextmenu = DisableRightClick;
    function DisableRightClick(){
    return false;
    }

  2. #2
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The link over here is the file name and my function is

    Download(parameter1,parameter2, parameter3,parameter4){
    redirects to the download page after doing some decision making according to the parameters passed
    }

    so the link is

    tahirjadoon.txt

    now in the href tag can i do some thing like as

    < a language="javascript" onMouseDown="">tahirjadoon.txt</a>

    In onMouseDown the following will go

    if(
    (e && (e.which == 1 || e.which == 2 || e.which = 0 || e.button = 1 || e.button == 2 || e.button == 0)) ||
    (window.event && (window.event.button == 2 || window.event.button == 1))
    ){
    Download(parameter1,parameter2, parameter3,parameter4)
    }

    Overhere one more thing, how can i get "e" like window.event?

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the late reply.

    Here's a basic, cross-browser event handler which assumes that all you need from the event object is 'keyCode':
    Code:
    function myEventListener(evt)
    {
      var e = evt ? evt : window.event;
      if(!e) return;
      var key = 0;
      if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
      else if (typeof(e.which) != 'undefined') { key = e.which; }
      // now the 'key' variable can be used... 
    }


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
  •