Skip to content

Instantly share code, notes, and snippets.

@hanguokai
Last active August 29, 2015 14:06
Show Gist options
  • Save hanguokai/f74ef1ab0eccb2d27da6 to your computer and use it in GitHub Desktop.
Save hanguokai/f74ef1ab0eccb2d27da6 to your computer and use it in GitHub Desktop.
Detect browser devtools console, and give a text when first open it. 用于在浏览器 console 上给开发者显示信息。
// 方法一:最简单的方法是直接在页面末尾加上这句话。
// 请替换具体文字内容。还可以为文字添加样式。
console && console.log("%cWelcome to here!\n", "font-size:1.5em;color:#4558c9;");
// 方法二:在打开 DevTools 时才提示,将下面代码添加到页面末尾。
(function(){
try{
function detect(){
if ((window.outerHeight - window.innerHeight) > 100 || (window.outerWidth - window.innerWidth) > 100){
// replace your text
console.log('Docked inspector was opened');
window.removeEventListener('resize', detect, true);
}
}
window.addEventListener('resize', detect, true);
} catch(e) {}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment