Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to prevent right click in a browser.

how to prevent right click in a browser.

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nettutorial
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    souravghosh18
    wrote on last edited by
    #1

    I am developing an ASP.NET application and i want to prevent the right click option for a particular page .How can it be achieved is there any javascript. Thanx in advance.

    M J C M 4 Replies Last reply
    0
    • S souravghosh18

      I am developing an ASP.NET application and i want to prevent the right click option for a particular page .How can it be achieved is there any javascript. Thanx in advance.

      M Offline
      M Offline
      Member 3851306
      wrote on last edited by
      #2

      Just Add this line in body tag oncontextmenu="return false;" Fastrythem

      1 Reply Last reply
      0
      • S souravghosh18

        I am developing an ASP.NET application and i want to prevent the right click option for a particular page .How can it be achieved is there any javascript. Thanx in advance.

        J Offline
        J Offline
        Jerry Wang
        wrote on last edited by
        #3

        <HTML>
        <script language="javascript">
        function preventEvt(evt)
        {
        evt.returnValue = false;
        if( evt.preventDefault ) evt.preventDefault();
        return false;
        }
        </script>
        <BODY oncontextmenu="return preventEvt(event)" onmousedown="return preventEvt(event)">

        </BODY>
        </HTML>

        This code can works in IE and Firefox, but no way in Opera

        1 Reply Last reply
        0
        • S souravghosh18

          I am developing an ASP.NET application and i want to prevent the right click option for a particular page .How can it be achieved is there any javascript. Thanx in advance.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          There are ways to convince an ignorant client that you did this, but I guarantee you that I can circumvent all of them, if I really wanted to right click on your web page.

          Christian Graus Driven to the arms of OSX by Vista.

          F 1 Reply Last reply
          0
          • S souravghosh18

            I am developing an ASP.NET application and i want to prevent the right click option for a particular page .How can it be achieved is there any javascript. Thanx in advance.

            M Offline
            M Offline
            monu nair
            wrote on last edited by
            #5

            function click(e) { if (document.all) { if (event.button == 2) { alert('Right Click Not Allowed'); return false; } } if (document.layers) { if (e.which == 3) { alert('Right Click Not Allowed'); return false; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=click; use this code in javascript

            Mahendra Bisht.

            1 Reply Last reply
            0
            • C Christian Graus

              There are ways to convince an ignorant client that you did this, but I guarantee you that I can circumvent all of them, if I really wanted to right click on your web page.

              Christian Graus Driven to the arms of OSX by Vista.

              F Offline
              F Offline
              fred_
              wrote on last edited by
              #6

              amen. What exactly are you trying to prevent?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups