今天无意中在百度知道页面打开了控制台,看到了控制台里居然有百度的logo
研究发现方法如下
if(!console){
console = {}
console.log = function(){}
}
function setConsoleImage(url){
var img = new Image();
img.style.display = "none";
document.body.appendChild(img);
img.src = url;
img.onload = function(){
var css = [
'padding: ' + (img.height/2 - 8) + 'px ' + img.width/2 + 'px;',
'line-height: ' + img.height +'px;',
'background-image: url(' + url + ');'
]
console.log('%c', css.join(''));
}
}
window.onload = function(){
setConsoleImage("xxx.jpg");
setConsoleImage("xxx.gif")
}