Web Analytics Made Easy -
StatCounter Disabling right-click - CodingForum

Announcement

Collapse
No announcement yet.

Disabling right-click

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disabling right-click

    Hi. What's the best way to display an image, disabling the user's ability to right-click on it?

    I believe you have to use <body oncontextmenu="return false">. Would the following work?

    var x = "<head><\/head><body oncontextmenu="return false"><img src='temp.jpg' border=0><\/body>"

    top.document.open()
    top.document.write(x)
    top.document.close()

    Since this is a frameless site, I don't think this would work, at least would never get to the close()...Dennis

  • #2
    Before you waste time disabling stuff, give up now. You can't stop people getting your images.

    Comment


    • #3
      Not only can you not prevent it, but you're introducing accessibility problems by trying. The right click does a lot more than "save as" - what if I want to open a link in a new window, add it to my favourites, or send some highlighted text to Google?
      "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

      Comment


      • #4
        <img oncontextmenu="return false;">

        but listen to all the resons why not to do it .

        Comment


        • #5
          This rather repetitive show is already running at

          http://www.codingforum.net/showthrea...threadid=33485

          The short answer is:

          a) you cannot protect your code or images from someone who is technically proficient and is determined to capture (steal) them.

          b) you can protect your code and images against people who have no knowledge of Javascript, which in fact is pretty well everyone.

          Even if the protection is of limited value it still makes it clear to the guy who is trying to capture your image that you do not permit him to do so and hence he must realise that he is a thief. I do appreciate that in this day and age many people are not too bothered by this appellation.

          All the code given in this post has been tested and is intended to address the question asked.
          Unless stated otherwise it is not just a demonstration.

          Comment


          • #6
            Originally posted by brothercake
            Not only can you not prevent it, but you're introducing accessibility problems by trying. The right click does a lot more than "save as" - what if I want to open a link in a new window, add it to my favourites, or send some highlighted text to Google?
            Here's a tip you may not have discovered - try clicking on that thing like two overlapping squares in the top right-hand corner of the screen, which makes it shrink down a bit and reveals a menu bar. Then you can select "Add to Favorites" and so on.

            Having said that, I am not too clear why you want to add to your favourites a site which you say you will never visit again because it offends you. Possibly a folder called "Abhorrances" or something?
            Last edited by Philip M; Feb 18, 2004, 03:17 AM.

            All the code given in this post has been tested and is intended to address the question asked.
            Unless stated otherwise it is not just a demonstration.

            Comment


            • #7
              Originally posted by Philip M
              a) you cannot protect your code or images from someone who is technically proficient and is determined to capture (steal) them.

              b) you can protect your code and images against people who have no knowledge of Javascript, which in fact is pretty well everyone
              You don't have to be technically proficient (I'm not) neither do you have to know Javascript. You simply have to be able to find the image in the Temporary Internet Files folder. No problem. Disabling the right-click is simply annoying and shows that the author is ignorant if he thinks he's protecting stuff.

              Comment


              • #8
                There is a technique which can be used to protect your images as well as a no-right-click script (that is to say, against those who don't know very much) but doesn't involve messing with the user interface.

                Code:
                <img src="transparentpixel.gif" style="height: 100px; width: 200px; background-image: url(myrealimage.jpg);" />
                Anyone right-clicking on the image and saving it will get the transparent pixel gif image. Of course the user could use the "Save Background As" menu item, delve the local cache examine the markup and directly download the image etc just like anyone with the knowledge of how to bypass a no right click script but it will provide protection against the same people who don't know how to bypass the no right click script and won't upset those who don't like such scripts.
                Check out the Forum Search. It's the short path to getting great results from this forum.

                Comment


                • #9
                  Originally posted by Roy Gardiner
                  You don't have to be technically proficient (I'm not) neither do you have to know Javascript. You simply have to be able to find the image in the Temporary Internet Files folder. No problem. Disabling the right-click is simply annoying and shows that the author is ignorant if he thinks he's protecting stuff.
                  Well, as I said before:

                  Even if the protection is of limited value it still makes it clear to the guy who is trying to capture your image that you do not permit him to do so and hence he must realise that he is a thief. I do appreciate that in this day and age many people are not too bothered by this appellation.

                  All the code given in this post has been tested and is intended to address the question asked.
                  Unless stated otherwise it is not just a demonstration.

                  Comment


                  • #10
                    Or you can try to force/trick the user into agreeing to abide to a ridiculous TOS like this.

                    Use of this Web site constitutes acceptance of the User Agreement

                    .....Willy

                    BTW: How's that for a TOS? Legally binding?

                    Comment


                    • #11
                      I think it is supposed to be a joke, Willy.
                      Tongue in cheek, you know? A sort of parody.
                      Probably intended to make you laugh.

                      All the code given in this post has been tested and is intended to address the question asked.
                      Unless stated otherwise it is not just a demonstration.

                      Comment


                      • #12
                        That's not a joke. The guy is serious!
                        If he has the resources to file a suit is another matter.

                        .....Willy

                        Comment


                        • #13
                          Originally posted by Philip M
                          Having said that, I am not too clear why you want to add to your favourites a site which you say you will never visit again because it offends you. Possibly a folder called "Abhorrances" or something?
                          Well I wouldn't ... and yeah there are ways to do its functions even it's not there ... but the point is the context menu is mine, it doesn't belong to the site I'm visiting. Websites have no right interfering with it.
                          "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

                          Comment


                          • #14
                            Out of my curiosity, some(many) on this site keep saying websites have no rite interferrring. yada yada etc....


                            anyway I was wondering since you guys so LIKE clear borders between the sites area and the clients what your stands on:

                            -pop up blocking(user blocking a feature that does not effect his user interface.)
                            -IMAGE/ADD blocking(user blocking a part of a site clear stepping beyond the bounds of his user interface.)

                            Comment


                            • #15
                              Here is my proposal to protect images, it would take a bit of coding, but should protect even against those with technical abilities.

                              You would need to store the images in a DB or on a part of the filesystem that is not accessable to the web.

                              You would need to do this in a language other then Javascript as Javascript is not powerfull enough.

                              Here is how it would work. When a page is loaded an encrypted key is generated at the start of the page.

                              The images would be refferenced via a script that would send the requested image id as well as the encrypted key. The script would then access the db and return the image and append the key to a field associated with the image's record. The ecrypted key would contain a time stamp as well, so the key would expire after 15 seconds, however if it is refferenced a second time within 15 seconds, it will return a blank image.

                              The key field would be checked for old keys every time the image is requested.


                              The script would contain code to prevent against the browser from caching the file, so if somone did a save as, when they requested the file from the server again they would be downloading a blank image.

                              Comment

                              Working...
                              X