开发者

How to detect Chrome Inspect Element is running or not? [duplicate]

This question already has answers here: Find out whether Chrome console is open 开发者_JS百科 (24 answers) Closed 9 years ago.

Is there any way to detect whether the Chrome Inspect Element window is running?

For example if the user clicks "Inspect Element" in Chrome, the window shows a Hello World alert.

Is that possible?


UPDATE This no longer works. The property console.profiles has been removed in Chrome 29.

The only solution that's left is checking the difference between window.outerHeight and window.innerHeight as suggested by @Gerben. There is a library devtools-detect based on this method which adds devtoolschange to the window object.

Alternatively, there is an effort in progress to create a Chrome extension using a more robust detection method, see this Google Group.


Here's how they check if DevTools are open in the first challenge of Discover DevTools interactive course:

function () {
    console.profile(); 
    console.profileEnd(); 
    if(console.clear) { console.clear() };
    return console.profiles.length > 0;
}


window.onresize = function(){
 if((window.outerHeight-window.innerHeight)>100)
   alert('hello');
}

In action: http://jsbin.com/ediquk/

Note that it seems like the resize event gets fired twice, so you should check whether you alerted the use already.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜