1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to disable left and right click on every pages

Discussion in 'HTML & JavaScript' started by camara, Jun 4, 2011.

  1. camara

    camara Newbie

    Joined:
    Dec 18, 2009
    Messages:
    15
    Likes Received:
    1
    how to disable left and right click on every pages

    any advice what script i have to use?

    thanks
     
  2. Alex Agamenon

    Alex Agamenon Registered Member

    Joined:
    Aug 4, 2010
    Messages:
    59
    Likes Received:
    1
    <body oncontextmenu="return false;">
     
    • Thanks Thanks x 1
  3. RootShellvb

    RootShellvb Junior Member

    Joined:
    Jan 29, 2009
    Messages:
    188
    Likes Received:
    211
    Occupation:
    CEO
    Location:
    Casablanca, Morocco
    Home Page:
    or include jQuery and insert in your page :
    Code:
    $(function() {
    ****$(this).bind("contextmenu", function(e) {
    ********e.preventDefault();
    ****});
    });
    
     
  4. ealexnet

    ealexnet Newbie

    Joined:
    Aug 3, 2010
    Messages:
    34
    Likes Received:
    6
    It's a VERY bad practice to disable or modify mouth actions on your web pages. What is the reason for disabling mouth clicks?
     
  5. GrizzlyAdams

    GrizzlyAdams Regular Member

    Joined:
    Feb 17, 2011
    Messages:
    479
    Likes Received:
    405
    Occupation:
    Freelancer
    Location:
    British Columbia
    Just don't think using that is going to protect you from any experienced computer user from finding out what you're trying to hide because it's very easy to get around it

    Shit+f10
     
  6. trudat

    trudat Registered Member

    Joined:
    Dec 29, 2009
    Messages:
    86
    Likes Received:
    18
    Location:
    New York
    Yeah, its pointless. Don't even worry about it. If people want your HTML then there is nothing you can do about it.
     
  7. SahL

    SahL Elite Member

    Joined:
    Jan 8, 2011
    Messages:
    1,594
    Likes Received:
    1,296
    Occupation:
    ★SEO expert and ★Sexpert
    Location:
    Bombay
    Home Page:
    disabling right click is fine ? bt why in world would you disable a left click ?
     
  8. no4h~

    no4h~ Regular Member

    Joined:
    Apr 11, 2011
    Messages:
    456
    Likes Received:
    330
    That's what I'm wondering... o_O
     
  9. seeplusplus

    seeplusplus Power Member

    Joined:
    Aug 18, 2008
    Messages:
    511
    Likes Received:
    163
    Copy and paste
     
  10. Roundhouse

    Roundhouse Regular Member

    Joined:
    Sep 22, 2009
    Messages:
    408
    Likes Received:
    212
    just encrypt your source html code if that is what you want to hide from the end user
     
  11. GreyWolf

    GreyWolf Executive VIP Jr. VIP

    Joined:
    Aug 17, 2009
    Messages:
    1,930
    Likes Received:
    5,389
    Gender:
    Male
    Occupation:
    Artist / Craftsman
    Location:
    sitting at my PC
    That would only disable the right-click.

    The OP says he wants to prevent visitors from doing a copy and paste from his page. To do that he also needs to disable the left-click. He can add some more commands into the body tag you gave so it will disable the left and right mouse clicks as well as keyboard commands.
    Code:
    <BODY oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
    If someone really wanted to copy anything though all they would need to do is view the page source and copy from there. As someone else mentioned he could encrypt the page source but the average visitor isn't going to bother checking the page source anyway. The ones that are going to go that far will likely be able to take the next step if they want to anyway.

    It's important to remember though that this should work for ie but won't work in all browsers. To give a better chance of working for more browsers he could also add the following code between the <head> </head> tags.
    Code:
    <script>
    var isNS = (navigator.appName == "Netscape") ? 1 : 0;
    
    if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
    
    function mischandler(){
    return false;
    }
    
    function mousehandler(e){
    var myevent = (isNS) ? e : event;
    var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
    }
    document.oncontextmenu = mischandler;
    document.onmousedown = mousehandler;
    document.onmouseup = mousehandler;
    
    </script>
    Even using both those codes won't work for all browsers though. Also when it does work the visitor won't be able to click any links on the page since the mouse clicks are disabled, it's only useful if he has no onpage navigation. The visitor will have to use the back button or close the browser tab to leave the page.
     
    • Thanks Thanks x 1
  12. hoodkist

    hoodkist Regular Member

    Joined:
    Jun 20, 2011
    Messages:
    241
    Likes Received:
    33
    Occupation:
    Web Designer and advertiser in marketing new softw
    Location:
    Beta testing your software
    Greywolf nailed it on the head with this one!!!