SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Location
    Spain
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript problem in Firefox - disable right click

    Please bear in mind I am a novice - EXTREME novice so I may be asking a very simple, stupid question. If so forgive me.

    I have what I think is a simple script that I use on my website to disable the use of right click to copy images etc. It works in IE but not Firefox.
    Here is the script

    var message="Thank you for visiting my site.\n\nCopying text and images is disabled on this page to protect Copyright. \n\nHowever if you want permission to use text or images please email me.\n\nThis Site Copyright 2011.";
    function click(e) {
    if (document.all) {
    if (event.button==2||event.button==3) {
    alert(message);
    return false;
    }
    }
    if (document.layers) {
    if (e.which == 3) {
    alert(message);
    return false;
    }
    }
    }
    if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    }
    document.onmousedown=click;
    I have read somewhere that the document.all and document.layers do not work in Firefox. If this is the case how so I achieve this in Firefox.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That code is aimed at IE4 and Netscape 4 browsers - it doesn't contain anything for more modern browsers that no longer use document.all and document.layers. It will work in some but not all of the more recent versions of IE but only if the browser security is set incorrectly.

    About ten years ago the ability to disable anything in the browser from JavaScript was been removed and control given to the owner of the browser. If they want to disable parts of the scripts you add to your page then they can but you can't disable any of the functionality of their browser without their permission.
    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="^$">

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This script will work unless disabled by user option.

    It has the advantage of working only when images are right-clicked, otherwise allowing the context menu.

    Code:
    <script type='text/javascript'>
    
     (function( imgStr  ) /** No right click ON IMAGES ONLY **/
     {
       function installHandler( obj, evt, func )
       {
         window.attachEvent ? obj.attachEvent( 'on' + evt, func ) : obj.addEventListener( evt, func, false );
       }
    
       function noImg( e /*2843294C6F676963416C69*/ )
       {
         if( /^(IMG|AREA)$/.test( ( e.target || e.srcElement ).nodeName ) )
         {
            if( imgStr )
              alert( imgStr );
    
            e.preventDefault ? e.preventDefault() : e.returnValue = false;
         }
       }
    
       installHandler( document, 'contextmenu', noImg );
       
     })( "To use images, please ask owner\'s permission." );  /** <-- Place your warning message between quotes or to display no message, leave as "" **/
    
    </script>
    Tab-indentation is a crime against humanity.

  4. #4
    SitePoint Member
    Join Date
    Mar 2013
    Location
    Spain
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    This script will work unless disabled by user option.

    It has the advantage of working only when images are right-clicked, otherwise allowing the context menu.
    Thank you very much! This works great.
    Does anyone know how I can stop the text being copied as well?
    I've had half my site ripped of by someone else and as I put a lot of effort into developing it I don't want someone else doing the same thing again.
    I know that you can override it in the browser settings but at least it's will stop the none savvy!

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by pommette View Post
    I know that you can override it in the browser settings but at least it's will stop the none savvy!
    It will definitely encourage those with a slight knowledge of how their browser works to steal your content just because they think that they are clever because they know how to bypass those trivial blocks. If they actually reduced the amount of theft then the major sites would implement that type of code but if anything it has the opposite effect.
    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="^$">

  6. #6
    SitePoint Member
    Join Date
    Mar 2013
    Location
    Spain
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help - will look at maybe buying some software to protect my source.
    One I've found is HTMLGuard. Do you know if this is ok or is there a better one?

  7. #7
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Personally I wouldn't bother with HTMLGuard, it's quite easy to bypass the code obfuscation they use just by downloading the supposedly encrypted page "Sample" I was able to view it and do copy-and-paste by just editing two characters making it totally useless.

  8. #8
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I can override any image blocking by merely tapping my PrtScn button, which captures the screen as an image, then opening it up in Photoshop and cropping it. These right-click scripts don't work for those who really want to get the image.
    Steve Husting

  9. #9
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can't stop someone from going to your page in the browser and hitting Edit > Copy, and copying the entire page to their hard drive, then opening that page in Notepad or TextEdit and editing it.

    Nowadays you can even highlight a PDF and copy the text, so PDF isn't the answer, either.
    Steve Husting

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by pommette View Post
    One I've found is HTMLGuard. Do you know if this is ok or is there a better one?
    The problem is that programs that will undo everything that programs like that one do to try to "protect" your page are easy to obtain - they are available as free downloads from many different web sites - they are called "web browsers".


    See http://www.felgall.com/net3k.htm for a series of articles I have written about web page protection. You can get all the various "protection" that is available from there at no charge (where some of the other equivalents will cost you several hundred dollars). You will also find there the much easier to implement scripts that will bypass all the "protection" of ALL programs that produce content that can be displayed in a web browser. So if you must annoy your legitimate visitors by implementing useless protection at least you will not have spent any money on it.
    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 Member
    Join Date
    Mar 2013
    Location
    Spain
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    See http://www.felgall.com/net3k.htm for a series of articles I have written about web page protection.
    Thanks Steve - looks like I have some bedtime reading to do!
    As a newby - you may well end up getting lots of questions though!!!


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
  •