我想在我的网页上添加一个按钮,当单击此按钮时,控制台将打开,就像用户单击键盘上的 (F12) 键时发生的情况一样。
这是我的尝试:
document.querySelector('#openConsole').addEventListener('click', () => {
var event = document.createEvent('Event');
event.initEvent('build', true, true);
event.keyCode = 123; // F12 key code
document.dispatchEvent(event);
});
<button id="openConsole">open console</button>
但是这不起作用!
最佳答案
开发工具无法以编程方式打开,因为这会导致不安全。
打开此控件将允许进行控制,然后可以通过注入(inject)数据等方式利用该控制。
关于javascript - 如何使用 JavaScript 触发打开控制台 (F12) 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51649419/