SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript - No Right Click on a Specific Image not all images

    I am writing my pages in XHTML Strict which does not have target=" " in the <a> tags
    so I use javascript to open some links in a new window

    and since not all of my visitors will know javascript
    some of them will click the right click and choose open in a new window and they will get ERROR
    and I will get 100s of emails saying your site sucks and your pages are missing

    I have buttons, I want to disable the right click on them so I do not get this problem. Not all of my page images ofcourse ..

    Is this possible?
    Mahmoud

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mahmoud,

    check out this javascript:

    <script language="JavaScript1.1">
    <!--
    function right(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
    return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
    alert("Cannot right click");
    return false;
    }
    return true;
    }

    document.onmousedown=right;
    document.onmouseup=right;
    if (document.layers) window.captureEvents(Event.MOUSEDOWN);
    if (document.layers) window.captureEvents(Event.MOUSEUP);
    window.onmousedown=right;
    window.onmouseup=right;
    // End -->
    </script>

    I had seen this used somewhere and copied it down. It effectively disables the right click option and displays an alert box. You can remove the line for the alert box and have nothing happen. This seems to work in IE but check out Netscape. Is this what you're looking for?

  3. #3
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, forgot to mention...for your problem, i was thinking that this code could be rewritten into a function whereby it gets called during an onclick event. When clicked, it evalutates if it is a right clicked or not. Thereby the images that you want to disable, you assign them an onclick event which calls this function.

  4. #4
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll check it out
    Mahmoud


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
  •