2

I am working on one project in which I disabled f12 and right click using jquery and its working fine. Code for it:

$(document).keydown(function(event){
 if(event.keyCode==123){
  return false;
 }
 else if(event.ctrlKey && event.shiftKey && event.keyCode==73){
    return false;  //Prevent from ctrl+shift+i
 }
});

$(document).on("contextmenu",function(e){
  e.preventDefault();
});

Is there any way so that I can click f12 key using jquery. I want this because I am facing one issue. eg. If google.com is already opened with insect element and then I load my page then it shows me inspect element. So I want to hide inspect window on page load.

Is there any way???

priya_singh
  • 2,478
  • 1
  • 14
  • 32
  • 2
    I feel the need for the obligatory users can easily get around these types of things, so *if* this is being used as some kind of security measure, it will only 1) annoy regular users who expect this website to work like others (highlight+right click+copy text for example), and 2) not hinder anybody trying to do anything nefarious. – TMH Mar 29 '17 at 11:04
  • Do you mean that you want to simulate a keypress onload? – FrankCamara Mar 29 '17 at 11:16
  • I agree with Tom, why would you ever want to do this? It won't stop people using the developer console if that is your intention... – Milney Mar 29 '17 at 11:16

2 Answers2

0

No it is not possible because f12 is attached with browser and not with page. JavaScript can only make communication with page.

Source: Handling key-press events (F1-F12) using JavaScript and jQuery, cross-browser

Community
  • 1
  • 1
0

Simply: You can't.

The Dev Tools are not sandboxed (unlike any web page), thus granting sandboxed environments the power to open and control an unsandboxed environment is a major security design flaw.

I hope this answers your question :-)

Dhiraj
  • 1,430
  • 11
  • 21