Disable right-click

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis Allen

    Disable 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.op en()
    top.document.wr ite(x)
    top.document.cl ose()

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


  • Lasse Reichstein Nielsen

    #2
    Re: Disable right-click

    "Dennis Allen" <dennis@dennisa llen.com> writes:
    [color=blue]
    > Hi. What's the best way to display an image, disabling the user's ability
    > to right-click on it?[/color]

    In general, no. (Not even disabling the effect of right-clicking :).

    Some browsers will allow it, but not all, and it is trivial to circumvent.
    [color=blue]
    > I believe you have to use <body oncontextmenu=" return false">.[/color]

    That will, in some browsers, disable the context menu for the entire
    page. Highly annoying a reason enough to leave the page.

    You can put it on the image itself instead:
    <img oncontextmenu=" return false;" src="..." alt="...">
    (remember, the "alt" tag is *required* for valid HTML).
    [color=blue]
    > Would the following work?
    >
    > var x = "<head><\/head><body oncontextmenu=" return false"><img
    > src='temp.jpg' border=0><\/body>"
    >
    > top.document.op en()
    > top.document.wr ite(x)
    > top.document.cl ose()[/color]

    Have you tried? What was the result?

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Hywel Jenkins

      #3
      Re: Disable right-click

      In article <10357a6hf8jtqd 5@corp.supernew s.com>, dennis@dennisal len.com
      says...[color=blue]
      > Hi. What's the best way to display an image, disabling the user's ability
      > to right-click on it?[/color]

      None.

      --
      Hywel I do not eat quiche


      Comment

      • Dennis Allen

        #4
        Re: Disable right-click

        Strangely enough, it did work. Use an <a href="temp.jpg"
        onclick=Display (this)>, which does:

        function Display(obj) {
        var img = obj.getAttribut e("href")
        var x = '<head><\/head><body oncontextmenu=" return false"><img alt=""
        src="'+img+'" border="0"><\/body>'
        top.document.op en()
        top.document.wr ite(x)
        top.document.cl ose()
        return false

        Of course this doesn't disable the file "Save As" for the web page. IE
        saved the "Display()" web page, but not the image itself. Is that because
        oncontent is disabled?

        As for why I need to do it, the client requested it...Dennis

        "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
        news:4qtpqobq.f sf@hotpop.com.. .[color=blue]
        > "Dennis Allen" <dennis@dennisa llen.com> writes:
        >[color=green]
        > > Hi. What's the best way to display an image, disabling the user's[/color][/color]
        ability[color=blue][color=green]
        > > to right-click on it?[/color]
        >
        > In general, no. (Not even disabling the effect of right-clicking :).
        >
        > Some browsers will allow it, but not all, and it is trivial to circumvent.
        >[color=green]
        > > I believe you have to use <body oncontextmenu=" return false">.[/color]
        >
        > That will, in some browsers, disable the context menu for the entire
        > page. Highly annoying a reason enough to leave the page.
        >
        > You can put it on the image itself instead:
        > <img oncontextmenu=" return false;" src="..." alt="...">
        > (remember, the "alt" tag is *required* for valid HTML).
        >[color=green]
        > > Would the following work?
        > >
        > > var x = "<head><\/head><body oncontextmenu=" return false"><img
        > > src='temp.jpg' border=0><\/body>"
        > >
        > > top.document.op en()
        > > top.document.wr ite(x)
        > > top.document.cl ose()[/color]
        >
        > Have you tried? What was the result?
        >
        > /L
        > --
        > Lasse Reichstein Nielsen - lrn@hotpop.com
        > DHTML Death Colors:[/color]
        <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
        > 'Faith without judgement merely degrades the spirit divine.'[/color]


        Comment

        • Richard Formby

          #5
          Re: Disable right-click


          "Dennis Allen" <dennis@dennisa llen.com> wrote in message
          news:1035ohmd9u 13845@corp.supe rnews.com...

          [right click disable]
          [color=blue]
          > As for why I need to do it, the client requested it...Dennis[/color]

          Demonstrate to your client how easy it is to left click on an image and drag
          it to your pictures folder.

          Cheers
          Richard.


          Comment

          • Steve

            #6
            Re: Disable right-click

            Here's How I do it.

            The code below in in a file called 'DisableRClick. js'
            Every page has :
            <script language="Javas cript" type="text/javascript"
            src"include/disableRClick.j s"></script>
            in its header

            DisableRClick.j s contains the code:

            document.oncont extmenu = function(){retu rn false}
            if(document.lay ers) {
            window.captureE vents(Event.MOU SEDOWN);
            window.onmoused own = function(e){
            if(e.target==do cument)return false;
            }
            }
            else {
            document.onmous edown = function(){retu rn false}
            }

            This works in IE and Mozilla - havn't test with Netscape yet.

            Steve

            "Dennis Allen" <dennis@dennisa llen.com> wrote in message
            news:10357a6hf8 jtqd5@corp.supe rnews.com...[color=blue]
            > 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.op en()
            > top.document.wr ite(x)
            > top.document.cl ose()
            >
            > Since this is a frameless site, I don't think this would work, at least
            > would never get to the close()...Denni s
            >
            >[/color]


            Comment

            • Randy Webb

              #7
              Re: Disable right-click

              Steve wrote:[color=blue]
              > Here's How I do it.
              >
              > The code below in in a file called 'DisableRClick. js'
              > Every page has :
              > <script language="Javas cript" type="text/javascript"
              > src"include/disableRClick.j s"></script>
              > in its header
              >
              > DisableRClick.j s contains the code:
              >
              > document.oncont extmenu = function(){retu rn false}
              > if(document.lay ers) {
              > window.captureE vents(Event.MOU SEDOWN);
              > window.onmoused own = function(e){
              > if(e.target==do cument)return false;
              > }
              > }
              > else {
              > document.onmous edown = function(){retu rn false}
              > }
              >
              > This works in IE and Mozilla - havn't test with Netscape yet.
              >[/color]

              No it doesn't, you just *think* it "works" there.


              --
              Randy
              Chance Favors The Prepared Mind
              comp.lang.javas cript FAQ - http://jibbering.com/faq/

              Comment

              • kaeli

                #8
                Re: Disable right-click

                In article <1035ohmd9u1384 5@corp.supernew s.com>, dennis@dennisal len.com
                enlightened us with...[color=blue]
                >
                > As for why I need to do it, the client requested it...Dennis
                >[/color]
                You might want to mention to your client that disabling the right click
                menu violates the accessibility rules.
                Disabled people use that menu to navigate. Some of us who aren't
                disabled use it, too.
                Disabling it is irritating, to say the least.

                And any idiot can drag and drop an image from IE.
                Any moron with an image editor can screen cap the page and edit the
                image. Slightly more IQ points and they can remove your digital
                watermark.
                Anyone with a moderate level of intelligence can read the source, get
                the link, and view it as an image by typing it in the address bar.

                Anyone can disable javascript and bypass anything you do with it.

                Sometimes, we need to save clients from themselves. heh

                --
                --
                ~kaeli~
                A plateau is a high form of flattery.



                Comment

                • eric garcia

                  #9
                  Re: Disable right-click

                  1st:

                  use the following code to disable right-click-period.
                  I got it from DynamicDrive.co m:

                  <script language=JavaSc ript>
                  <!--

                  //Disable right mouse click Script
                  //By Maximus (maximus@nsimai l.com) w/ mods by DynamicDrive
                  //For full source code, visit http://www.dynamicdrive.com

                  var message="Functi on Disabled!";

                  ///////////////////////////////////
                  function clickIE4(){
                  if (event.button== 2){
                  alert(message);
                  return false;
                  }
                  }

                  function clickNS4(e){
                  if (document.layer s||document.get ElementById&&!d ocument.all){
                  if (e.which==2||e. which==3){
                  alert(message);
                  return false;
                  }
                  }
                  }

                  if (document.layer s){
                  document.captur eEvents(Event.M OUSEDOWN);
                  document.onmous edown=clickNS4;
                  }
                  else if (document.all&& !document.getEl ementById){
                  document.onmous edown=clickIE4;
                  }

                  document.oncont extmenu=new Function("alert (message);retur n false")

                  // -->
                  </script>

                  Then add this to your META Tag section up in your Page's Head section:

                  <meta http-equiv="imagetoo lbar" content="no">
                  <meta http-equiv="imagetoo lbar" content="false" >




                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  • Randy Webb

                    #10
                    Re: Disable right-click

                    eric garcia wrote:
                    [color=blue]
                    > 1st:
                    >
                    > use the following code to disable right-click-period.[/color]

                    No. You use that worthless, non-working garbage to attempt to disable
                    it. It does *not* disable the right click.
                    [color=blue]
                    > I got it from DynamicDrive.co m:[/color]

                    Give it back. Its useless.

                    <--snip-->
                    [color=blue]
                    > Then add this to your META Tag section up in your Page's Head section:
                    >
                    > <meta http-equiv="imagetoo lbar" content="no">
                    > <meta http-equiv="imagetoo lbar" content="false" >[/color]

                    That does nothing in my browser. But even in IE6, I don't even need to
                    use my mouse to get anything in the page. File>Save As and there it is.
                    Every bit of it.

                    --
                    Randy
                    comp.lang.javas cript FAQ - http://jibbering.com/faq

                    Comment

                    Working...