SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    disabling right clicks

    Hello

    I saw quite a few scripts that allow the user to disable the right-click on certain components (usually images).

    This is what the code looked like (for IE);
    Code:
    function disableRightClick() {
      if (event.button == 2) {	
        alert("Sorry, right-click is disabled");
        return false;
      }
    }
    Then call this function like so:
    Code:
    <a href="test.html" onmousedown="disableRightClick();">test</a>
    I would like to disable right-clicks without the annoying alert.
    I just don't want the menu to open when the user right-clicks the link.
    Is that possible?
    When I remove the call to alert, then the code has no effect.

    thanks

  2. #2
    SitePoint Enthusiast #lama's Avatar
    Join Date
    Jun 2004
    Location
    Prague, Czech Republic
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by davidklonski
    Hello

    I saw quite a few scripts that allow the user to disable the right-click on certain components (usually images).

    This is what the code looked like (for IE);
    Code:
    function disableRightClick() {
      if (event.button == 2) {	
        alert("Sorry, right-click is disabled");
        return false;
      }
    }
    Then call this function like so:
    Code:
    <a href="test.html" onmousedown="disableRightClick();">test</a>
    I would like to disable right-clicks without the annoying alert.
    I just don't want the menu to open when the user right-clicks the link.
    Is that possible?
    When I remove the call to alert, then the code has no effect.

    thanks
    Code:
    function disableRightClick() {
      if (event.button == 2) {
        
        return false;
      }
    }
    http://halogan.xblog.cz - my weblog (czech only)

    Sorry for my weak English, I'm still learning.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said in the original posting:
    When I remove the call to alert, then the code has no effect.
    This is not the solution.


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
  •