[英]Distinguish javascript of Console & Browser
Is there a way to distinguish javascript code that belongs to a website and javascript code that is run from the Console tab in Chrome DevTools? 有没有办法区分属于网站的javascript代码和从Chrome DevTools的“控制台”标签中运行的javascript代码?
What I'm trying to do is the following: 我想做的是以下几点:
Initialize a DEBUG
variable to true
when I copy paste my javascript code to the Console and false
when the javascript code is either located in a <script>
tag inside the html file or downloaded from the browser as in an external .js
file. 当我将JavaScript代码复制粘贴到控制台时,将DEBUG
变量初始化为true
;而当JavaScript代码位于html文件内的<script>
标记中或从浏览器下载时(如外部.js
文件中),则将DEBUG
变量初始化为false
。
The console has a few global functions. 该控制台具有一些全局功能。 You can do: 你可以做:
var DEBUG = typeof clear === 'function'; // clear() is a global in the console to clear the screen
Just make sure you don't define a global variable clear
. 只要确保您没有定义全局变量clear
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.