How can I disable drag and drop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mclerp
    New Member
    • Jun 2008
    • 3

    How can I disable drag and drop?

    I want to disable copying picture files from an HTML file. I have purchased "Activ eBook Compiler" software which disables left-click copying, printing, and Alt+PrtScr copying to clipboard but it still doesn't disable drag & drop. I realise that a knowledgeable computer user would be able to get around most attempts to disable copying but I want to, at least, make it difficult. I have tried:

    [HTML]<BODY onBeginDrag="re turn FALSE ;"> [/HTML]

    and:

    [HTML]<img src=”mypic.jpg” ondrag=”return false;” />[/HTML]

    but neither command has any effect in my browser (IE7) in XP Pro.

    Can anyone help please?
    Last edited by gits; Jul 2 '08, 06:15 AM. Reason: added code tags
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    Moving to JavaScript Forum.

    --Kevin

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      There's no cross-browser ondrag event. Drag/drop depends on the onmousemove/up/down events.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        There is nothing that can prevent your images from being copied.
        But yeah, for disabling the drag thing, use onmousedown = "return false;" in the body tag.

        But this will ruin your inputs and textareas, as this will not let the user to move focus to them with mouse click.

        So if there's any input or textarea in your page, there's another way out (a bit lengthy, so will tell you only if you need).

        For disabling right click, use oncontextmenu = "return false;" in body tag. But this is not compatible attribute with the standard modes. So rather do it with JavaScript.

        Comment

        • jeffjustice
          Banned
          New Member
          • Jul 2008
          • 9

          #5
          Maybe you can find some help here: DELETED

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            What does that have to do with the original question?

            Comment

            • RamananKalirajan
              Contributor
              • Mar 2008
              • 608

              #7
              Respected Sir,
              I am not sure that whether I am giving the correct answer but somehow this will help you to prevent your picture copied.

              Code:
              <html>
              <head>
                <script langauge="javascript">
                function onDrag()
                {
                  alert("selected");     
                }
                </script>
              </head>
              <body>
              <div id="myDic" onmousedown="onDrag()">
              <br/>
               <img src="1.jpg" >
              <br/>
              </div>
              <br/>
              </body>
              </html>
              Just try this one.

              Regards
              Ramanan Kalirajan

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Isn't onmousedown = "return false;" a better option?

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  To protect images, watermark them. As soon as you display them on your page and someone visits it, it's been downloaded, so any script won't protect an image.

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    When I was in college, an assoicate of mine was working on something sneaky.
                    He had an html page (on his server) with images. And a challenge to try and get a copy of them without using the printscreen(scr een capture) button.
                    If you higlighted the image, it changed.
                    If you right-clicked and said save image, it was a different image.
                    if you went to the URL of the image, it was a different image.

                    I don't know how he did it, but he was sneaky like that.

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by acoder
                      To protect images, watermark them. As soon as you display them on your page and someone visits it, it's been downloaded, so any script won't protect an image.
                      Moreover there's a "Prt Scr" key.

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by hsriat
                        Moreover there's a "Prt Scr" key.
                        True, though the OP said this key was disabled. One simple way to protect the content would be to create a transparent div over the content. No matter where the user clicks, they can't get at the content. The only way they can get the image is by viewing the source and finding the image source, or modifying the source to remove the div.

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by Plater
                          When I was in college, an assoicate of mine was working on something sneaky.
                          He had an html page (on his server) with images. And a challenge to try and get a copy of them without using the printscreen(scr een capture) button.
                          If you higlighted the image, it changed.
                          If you right-clicked and said save image, it was a different image.
                          if you went to the URL of the image, it was a different image.

                          I don't know how he did it, but he was sneaky like that.
                          Could you not check the source or disable scripting?

                          Comment

                          • mclerp
                            New Member
                            • Jun 2008
                            • 3

                            #14
                            Originally posted by RamananKaliraja n
                            Respected Sir,
                            I am not sure that whether I am giving the correct answer but somehow this will help you to prevent your picture copied.

                            Code:
                            <html>
                            <head>
                              <script langauge="javascript">
                              function onDrag()
                              {
                                alert("selected");     
                              }
                              </script>
                            </head>
                            <body>
                            <div id="myDic" onmousedown="onDrag()">
                            <br/>
                             <img src="1.jpg" >
                            <br/>
                            </div>
                            <br/>
                            </body>
                            </html>
                            Just try this one.

                            Regards
                            Ramanan Kalirajan


                            Thank you for the solution to my problem. This routine, combined with the eBook Compiler software, disables all copying after the files are compiled. Your help is very much appreciated ..... mclerp

                            Comment

                            • mclerp
                              New Member
                              • Jun 2008
                              • 3

                              #15
                              Originally posted by hsriat
                              There is nothing that can prevent your images from being copied.
                              But yeah, for disabling the drag thing, use onmousedown = "return false;" in the body tag.

                              But this will ruin your inputs and textareas, as this will not let the user to move focus to them with mouse click.

                              So if there's any input or textarea in your page, there's another way out (a bit lengthy, so will tell you only if you need).

                              For disabling right click, use oncontextmenu = "return false;" in body tag. But this is not compatible attribute with the standard modes. So rather do it with JavaScript.


                              Thank you for your help. I haven't been able to get this to work but that's probably because I don't know how to write the full code. As a Newbie, I am VERY new and haven't written any Java script before. However, the routine described by RamananKaliraja n works well. Thanks to everyone who has replied to my question ..... mclerp

                              Comment

                              Working...