[英]How can I make custom messages appear in the console section when people open dev tools on my site?
I recently opened dev tools on Reddit.com and Facebook.com and both of them have custom messages displayed to developers who open the console on their site. 我最近在Reddit.com和Facebook.com上打开了开发工具,这两个工具都有向开发人员显示的自定义消息,这些开发人员在其网站上打开控制台。 Reddit has an ad that recruits developers and facebook has a warning in the console section warning people not to paste in code that could result in their account getting hijacked.
Reddit的广告招募开发人员,facebook在控制台部分警告,警告人们不要粘贴可能导致其帐户被劫持的代码。
How can I achieve something like this? 我怎样才能实现这样的目标? Is this a part of the Header or footer in HTML?
这是HTML页眉或页脚的一部分吗?
If you look at the source of Reddit in the dev tools you will find a line that looks like this: 如果您在开发工具中查看Reddit的源代码,则会发现一行如下所示:
console.log("\n ,d\"=≥,.,qOp,\n ,7' ''²$( )\n ,7' '?q$7'\n ..,$$,.\n ,. .,,--***²\"\"²***--,,. .,\n ² ,p²'' ''²q, ²\n: ,7' '7, :\n ' $ ,db, ,db, $ '\n '$ ²$$² ²$$² $' Using Reddit at work? Work for Reddit.\n '$ $' https://www.reddit.com/jobs\n '$. ., ,. .$'\n 'b, '²«»«»«»²' ,d'\n '²?bn,, ,,nd?²'\n ,7$ ''²²²²²²²²'' $7,\n ,² ²$ $² ²,\n $ :$ $: $\n $ $ $ $\n 'b q: :p d'\n '²«?$. .$?»²'\n 'b d'\n ,²²'?,. .,?'²²,\n ²==--≥²²==--==²²≤--==²\n")
It's just a console.log()
statement. 这只是一个
console.log()
语句。 You can open the snippet below and try it yourself: 您可以打开以下代码段,然后自己尝试:
console.log("\\n ,d\\"=≥,.,qOp,\\n ,7' ''²$( )\\n ,7' '?q$7'\\n ..,$$,.\\n ,. .,,--***²\\"\\"²***--,,. .,\\n ² ,p²'' ''²q, ²\\n: ,7' '7, :\\n ' $ ,db, ,db, $ '\\n '$ ²$$² ²$$² $' Using Reddit at work? Work for Reddit.\\n '$ $' https://www.reddit.com/jobs\\n '$. ., ,. .$'\\n 'b, '²«»«»«»²' ,d'\\n '²?bn,, ,,nd?²'\\n ,7$ ''²²²²²²²²'' $7,\\n ,² ²$ $² ²,\\n $ :$ $: $\\n $ $ $ $\\n 'bq: :p d'\\n '²«?$. .$?»²'\\n 'b d'\\n ,²²'?,. .,?'²²,\\n ²==--≥²²==--==²²≤--==²\\n")
You can get color in the browser's console with code like (it won't work in a SO snippet, but if you copy/paste into the browser console it will): 您可以使用以下代码在浏览器的控制台中获取颜色(在SO代码段中不起作用,但是如果将其复制/粘贴到浏览器控制台中,则可以):
console.log('%c This is reversed! ', 'background: #ee11cc; color: #eee');
You can find the code for the ad by searching in the source as well. 您也可以通过在源代码中搜索来找到广告代码。
You can write to the console with the console.log() command. 您可以使用console.log()命令写入控制台。
https://www.w3schools.com/js/js_output.asp https://www.w3schools.com/js/js_output.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.