Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<body oncontextmenu="return false;">

JavaScript
<script type="text/javascript">         
var elements = document.getElementsByTagName("body");             
  for(var id = 0; id < elements.length; ++id)
  {                      
         elements[id].>

is their any way to achieve both disable and re-enable right click on same page
Posted
Updated 27-Aug-15 1:17am
v2
Comments
Sanket Saxena 27-Aug-15 7:08am    
Where is the question? Didn't getting your point with this small info.
Design5ud 27-Aug-15 7:24am    
i have gallery.html page for that , i want to first disable the right click , so i used in <body oncontextmenu="return false;"> and after login i want to re-enable the right click to the same gallery.html page.
Sanket Saxena 27-Aug-15 7:40am    
I update my solution. Check on your page if it helps.
F-ES Sitecore 27-Aug-15 7:36am    
It might be easier to do this if you do it at an event level rather than adding an attribute. In js you should be able to attach your function to the contextmenu event, then remove the handler when needed.

Personally I wouldn't bother though. Unless you are providing your own context menu all you're going to do is annoy your users, and if you think you're stopping them from viewing the source, going back, printing, copying or anything else you're probably trying to do then you're not. They can still do all those things from elsewhere.

1 solution

After login you can write the document.ready method of jquery and the inside it just remove the attribute from the body tag.

example:
JavaScript
<script type="text/javascript">
 $(document).ready(function() {
      $('body').attr( "oncontextmenu");
  });

<script>


If dont want to use jQuery then can manage by javascript also:

document.getElementById("body").removeAttribute("oncontextmenu");


Hope it helps :)
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900