简体   繁体   English

当人们在我的网站上打开开发工具时,如何使自定义消息出现在控制台部分?

[英]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.

相关问题 如何使导航栏出现在某个部分? - How can I make my navbar appear at a certain section? 如何使导航出现在网页的特定部分? - How can I make my navigation appear on a certain section of my webpage? 如何让 React 开发工具在本地工作? - How can I make React dev tools work locally? 我可以在console.debug()并使Chrome Dev-tools断点在那里吗? - Can I console.debug() and make Chrome Dev-tools breakpoint there? 如何在我的网站上创建实时线程(vidiprinter)类型部分? - How can I make a live thread (vidiprinter) type section of my site? 如果年龄合适,我该如何创建一个年龄限制的站点来将人们带到另一个站点? - How Can I Make an Age Restricted Site that brings people to another site if age is good? 如何隐藏带有CSS或MetaTag或其他项目的Chrome Dev Tools Console,资源和其他标签? - How can I hide Chrome Dev Tools Console,Resources and other tabs with CSS or MetaTag or other items? 如何将开发工具控制台 scope 更改为本地 function? - How do I change dev tools console scope to be local to a function? 我如何有一个搜索框,人们可以在其中搜索我站点内的页面? - How can I have a search box where people can search for pages within my site? Javascript +浏览器-如何检测何时打开开发工具/ firebug? - Javascript + Browser - How to detect when dev tools / firebug is open?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM