SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post the always detested disable right click script

    Hello fellow webmasters. Nice to see this site again... was a member back in 2000 and occasionally would pop in over the years. Always found great info here! I am a self taught webmaster, but by no means any expert. I had a few very successful sites that I ended up selling so I could take a break. Now I am just hanging out on the web… anyhoo…


    My question is going to get flamed big time, I know... it's about disabling right click on images only without an alert. I have been around, I know that this method doesn't protect your images, I know this method is seriously frowned upon, as I can't stand it either… but this is more for a special case, and NOT for my website by any means.

    The 3 main scripts I have located are:

    Disables right click entirely with an alert

    Code JavaScript:
    <script language=JavaScript>
    <!--
     
    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //For full source code, visit [url]http://www.dynamicdrive.com[/url]
     
    var message="Function Disabled!";
     
    ///////////////////////////////////
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }
     
    function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
    alert(message);
    return false;
    }
    }
    }
     
    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }
     
    document.oncontextmenu=new Function("alert(message);return false")
     
    // --> 
    </script>

    Disables right click on images only with an alert

    Code JavaScript:
    <script language="JavaScript1.2">
     
    /*
    Disable right click script II (on images)- By Dynamicdrive.com
    For full source, Terms of service, and 100s DTHML scripts
    Visit [url]http://www.dynamicdrive.com[/url]
    */
     
    var clickmessage="Right click disabled on images!"
     
    function disableclick(e) {
    if (document.all) {
    if (event.button==2||event.button==3) {
    if (event.srcElement.tagName=="IMG"){
    alert(clickmessage);
    return false;
    }
    }
    }
    else if (document.layers) {
    if (e.which == 3) {
    alert(clickmessage);
    return false;
    }
    }
    else if (document.getElementById){
    if (e.which==3&&e.target.tagName=="IMG"){
    alert(clickmessage)
    return false
    }
    }
    }
     
    function associateimages(){
    for(i=0;i<document.images.length;i++)
    document.images[i].onmousedown=disableclick;
    }
     
    if (document.all)
    document.onmousedown=disableclick
    else if (document.getElementById)
    document.onmouseup=disableclick
    else if (document.layers)
    associateimages()
    </script>

    Disables right click entirely without an alert

    Code JavaScript:
    <script language=JavaScript>
    <!--
     
    //Disable right click script III- By Renigade (renigade@mediaone.net)
    //For full source code, visit [url]http://www.dynamicdrive.com[/url]
     
    var message="";
    ///////////////////////////////////
    function clickIE() {if (document.all) {(message);return false;}}
    function clickNS(e) {if 
    (document.layers||(document.getElementById&&!document.all)) {
    if (e.which==2||e.which==3) {(message);return false;}}}
    if (document.layers) 
    {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
    else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
     
    document.oncontextmenu=new Function("return false")
    // --> 
    </script>


    I don't know JavaScript well enough to figure out how to disable right click on images only without that alert poping up.

    If anyone has any input on the script, it would be greatly appreciated. Please, don't bash me for bring up this subject... I know this method is bad and doesn't protect anything. LOL

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    With the scripts that disable right-click on images, remove the lines that start with "alert"
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    most modern browsers either disregard such scripts or have an option to disable those calls within the javaScript. The mouse button will only be disabled if your visitor wants it disabled.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Evangelist asprookie's Avatar
    Join Date
    May 2005
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Been using this right-click diseable method for years and will not abandon it.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    It just provides a fairly low fence to jump over. The menus duplicate most of the right-click functionality and the rest of it, like saving images, is easily achieved by, for example, dragging an image from the Web page onto the desktop.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    In Opera no right click scripts are ignored by default.

    In Firefox no right click scripts can be ignored or not depending on how you configure the browser.

    Any browser that supports bookmarklets can have a disable no right click scripts bookmarklet installed to disable the script on any page that uses it.

    Few no right click scripts disable the button on the keyboard that also brings up the same menu as right clicking does.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    With the scripts that disable right-click on images, remove the lines that start with "alert"
    this does not work.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Please post the updated code
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    <script language="JavaScript1.2">
     
    /*
    */
     
    var clickmessage="Right click disabled on images!"
     
    function disableclick(e) {
    if (document.all) {
    if (event.button==2||event.button==3) {
    if (event.srcElement.tagName=="IMG"){
     
    return false;
    }
    }
    }
    else if (document.layers) {
    if (e.which == 3) {
     
    return false;
    }
    }
    else if (document.getElementById){
    if (e.which==3&&e.target.tagName=="IMG"){
     
    return false
    }
    }
    }
     
    function associateimages(){
    for(i=0;i<document.images.length;i++)
    document.images[i].onmousedown=disableclick;
    }
     
    if (document.all)
    document.onmousedown=disableclick
    else if (document.getElementById)
    document.onmouseup=disableclick
    else if (document.layers)
    associateimages()
    </script>

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The following code will work exactly the same as that in most browsers.

    Code:
    
    
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    SitePoint Addict Iceman90's Avatar
    Join Date
    Mar 2006
    Location
    Calgary, Alberta, Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL felgall.

  12. #12
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    funny


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
  •