[RESOLVED]Disable Right Click

How to disable right click iframe using JavaScript in asp.net ?

Why do you want to do this?

i just want know about it.

Well, the short answer is that it’s pointless to do this. Search the forums, as this has been asked many times.

Hi bora long,

bora long

How to disable right click iframe using JavaScript in asp.net ?

For this issue, you could use oncontextmenu Event. Please refer to this sample.

Code in Page (IframeTest.aspx)

        function DisRigthtClick() {
            alert("Disable Rigtht Click!");
            return false;
        }

        <iframe id="iframeId" oncontextmenu="DisRigthtClick()" src="IframePage.aspx"></iframe>

Code in Page (IframePage.aspx)

    <script type="text/javascript">
        function DisRigthClick() {
            alert("Disable Right Click Event!");
            return false;
        }
    </script>

<body oncontextmenu="DisRigthClick();" >

For more information about oncontextmenu Event, please refer to this article.

http://www.w3schools.com/jsref/event_oncontextmenu.asp

Best Regards,
Dillion

Hi,

Please use below code.

<script type="text/javascript">

 $(function () {
        $(document).bind(‘contextmenu’, function (e) {
            e.preventDefault();

        });
    });

</script>

bora long

i just want know about it.

No, you want to stop people doing a copy and paste, viewing the url or viewing the source.  All of which are impossible as there are 100 ways I could do these tasks without using the right-click, or I could just disable javascript (no, you can’t stop people
doing that either).  As you’ve already been told, don’t waste your time even trying.

Leave a Reply