Results 1 to 3 of 3

Thread: How to capture right click and disable context menu?

  1. #1
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to capture right click and disable context menu?

    Problem : How to capture right click from inside <a> tag or <img > tag through onmousedown or onmouseup events and disable context menu?

    Below is the code I have tried to implement.

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    
    function myhandler(e)
    {
          //// do something with event obj......
         return false;
    }
    
    //-->
    </SCRIPT>
    
    <a href="http://www.yahoo.com"  onmousedown="return myhandler(event);"
    onmouseup="return myhandler(event);" 
    onclick="return myhandler(event);">
    Right click should be disabled on this item.</a>
    I want to disable right click only on particular links or images. So I wrote the above code. What is wrong with above code. Why does the browser not responding to return false; I just want to capture mouse events and use them as per my purpose and then disable them all by returning false.

    I think onclick is working fine and so the browser is not going to yahoo.com But when you right click, none of the code is working. It is displaying right context menu of the browser.

    I know how to add event listener to a particular ID. But what I dont want to write code for particualr IDs. I want to capture right click event from inside of <a href> tag or <img> tag where ever I need it and then disable right context menu.

    Hope somebody will work out what is wrong with above code.

    A working cross browser example will be fabulous.

    Thanking you.

    Afru.

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A working cross browser example will be fabulous.
    Correction: Impossible.

    It's never a good idea to use these kinds of scripts. If you put information on the internet, there is always a way to get that information. You can never make information secure, which renders all scripts of this sort useless. They also highly infuriate users of all types.

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  3. #3
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry to say that I dont need this script to secure pages. I agree with your saying that there is always a way to get that information.

    My idea is to have different right click javascript menus for different elements or links on the site.

    So that you can create right click menu for images, links and even table cells. I know how to write it by using add listener to document but it will make only one menu for the whole document. I think you understand what I am upto.

    If you have a bit time, can you please post how to check event object in the handler function to disable default context menu of the browser.

    Thanking you,

    Afru.

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
  •