Hao Dong
Hao Dong

Reputation: 53

How can I detect the Developer Tools is running on IE 10 with JavaScript?

How can I detect the Developer Tools is running on IE 10 with JavaScript?

I tried:

if (console && console.log) {
   alert("Developer tools is running");
}

Upvotes: 0

Views: 1424

Answers (4)

Martin
Martin

Reputation: 3286

In IE 10 you can call

window.__IE_DEVTOOLBAR_CONSOLE_COMMAND_LINE

if it is an object the toolbar is open. (Be careful: it stays if you have opened the toolbar in the same 'window' before) if it is 'undefined' the toolbar is closed.

Upvotes: 1

Sin
Sin

Reputation: 1

As Arbitter and Jazza have already stated, it's not really possible.

Perhaps not useful to you but the only way I've been able to interact with the Developer Tools is using the JavaScript statement:

debugger;

This will cause a breakpoint to be hit if debugging with Developer Tools.

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FStatements%2Fdebugger

Upvotes: 0

jdepypere
jdepypere

Reputation: 3553

AFAIK not really possible. if( console.log ) would check if console.log() is an available function, so it will return true.

http://jsfiddle.net/cXBL9/

But of course this has nothing to do dev whether the tools are open or not.

Upvotes: 0

Jared
Jared

Reputation: 3016

In previous versions of IE and in all other modern browsers you can't tell if the Developer Tools or Web Inspector are open. I assume the same is for IE10.

You can check if the browser supports console logging by using:

if ('console' in window) {
    if ('log' in console) {
        console.log('This will work.');
    }
}

IE8 and below may not support console logging, so it's wise to check if they do before logging to the console in your code.

Upvotes: 0

Related Questions