search
HomeWeb Front-endHTML Tutorialfirebug console description_html/css_WEB-ITnose

Console is the first and most important panel of Firebug. Its main function is to display various information generated during the loading process of web pages.

1. Commands to display information

Firebug has a built-in console object that provides 5 methods for displaying information.

The simplest method is console.log(), which can be used to replace alert() or document.write(). For example, if you use console.log("Hello World") in a web script, the console will automatically display the following content when loading.

In addition, according to the different nature of the information, the console object has 4 ways to display information, namely general information console.info(), debugging information console.debug(), Warning prompt console.warn(), error prompt console.error().

For example, insert the following four lines into the web script:

console.info("This is info");

console.debug("This is debug") ;

console.warn("This is a warn");

console.error("This is an error");

When loading, the console will display the following content .

As you can see, there are different icons in front of information of different natures, and there are hyperlinks behind each piece of information. Click to jump to the corresponding line of the web page source code.

2. Placeholders

The above five methods of the console object can all use printf style placeholders. However, there are relatively few types of placeholders, and only four types of placeholders are supported: characters (%s), integers (%d or %i), floating point numbers (%f), and objects (%o).

For example,

console.log("%d year %d month %d day", 2011,3,26);

console.log("Pi is %f",3.1415926);

%o placeholder, which can be used to view the internal conditions of an object. For example, there is such an object:

var dog = {} ;

dog.name = "Big Hair" ;

dog.color = "yellow";

Then, use o% placeholder for it.

console.log("%o",dog);

3. Group display

If there is too much information, you can display it in groups, use The available methods are console.group() and console.groupEnd().

console.group("The first group of information");

console.log("The first message of the first group");

console.log("The first A group of second items");

console.groupEnd();

console.group("Second group of information");

console.log(" The first item in the second group");

console.log("The second item in the second group");

console.groupEnd();

Click the group title and the group information will collapse or expand.

4. console.dir()

console.dir() can display all the properties and methods of an object.

For example, now add a bark() method to the dog object in Section 2.

dog.bark = function(){alert("bark woof");};

Then, display the content of the object,

console.dir(dog) ;

5. console.dirxml()

console.dirxml() is used to display the html/xml code contained in a node of the web page.

For example, first get a table node,

 var table = document.getElementById("table1");

Then, display the code contained in the node.

console.dirxml(table);

6. console.assert()

console.assert() is used to judge an expression or Whether the variable is true. If the result is no, a corresponding message is output to the console and an exception is thrown.

For example, the results of the following two judgments are both no.

var result = 0;

console.assert( result );

var year = 2000;

console.assert(year == 2011 ) ;

7. console.trace()

console.trace() is used to trace the calling trace of the function.

For example, there is an adder function.

Function add(a,b){

Return a b;

}

I want to know how this function is called, add it in The console.trace() method will do the trick.

function add(a,b){

console.trace();

return a b;

}

Assume this The function calling code is as follows:

var x = add3(1,1);

function add3(a,b){return add2(a,b);}

Function add2(a,b){return add1(a,b);}

Function add1(a,b){return add(a,b);}

After running, The call trace of add() will be displayed, which is add(), add1(), add2(), and add3() from top to bottom.

8. Timing function

console.time() and console.timeEnd() are used to display the running time of the code.

console.time("Timer One");

for(var i=0;i

for(var j=0; j

 }

 console.timeEnd("Timer One");

9. Performance Analysis

Performance analysis (Profiler) is to analyze the running time of each part of the program. To find out where the bottleneck is, the method used is console.profile().

Suppose there is a function Foo(), which calls two other functions funcA() and funcB(), of which funcA() is called 10 times and funcB() is called once.

function Foo(){

for(var i=0;i

funcB(10000);

 }

 function funcA(count){

 for(var i=0;i

 }

Function funcB(count){

for(var i=0;i

 }

Then, you can analyze Foo() Running performance.

console.profile('Performance Analyzer One');

Foo();

console.profileEnd();

The console will display A performance analysis table, as shown below.

The title bar indicates that a total of 12 functions were run, taking a total of 2.656 milliseconds. Among them, funcA() runs 10 times, taking 1.391 milliseconds, the shortest running time is 0.123 milliseconds, the longest running time is 0.284 milliseconds, and the average is 0.139 milliseconds; funcB() runs once, taking 1.229ms.

In addition to using the console.profile() method, firebug also provides a "Profiler" button. When you click the button for the first time, "Performance Analysis" starts, and you can perform certain operations on the web page (such as ajax operations). Then when you click the button for the second time, "Performance Analysis" ends, and all operations triggered by this operation will be performed. Performance analysis.

10. Properties Menu

After the name of the console panel, there is an inverted triangle. After clicking, the properties menu will be displayed.

By default, the console only displays Javascript errors. If you select Send Javascript warnings, CSS errors, and XML errors, the relevant prompt information will be displayed.

The more useful thing here is "show XMLHttpRequests", which is to display ajax requests. After selecting, all ajax requests of the web page will be displayed in the console panel.

For example, if we click on a YUI example, the console will tell us that it issued a GET request using ajax. The header information and content body of the http request and response can also be seen.

[Reference]

* Firebug Tutorial - Logging, Profiling and CommandLine (Part I)

* Firebug Tutorial - Logging, Profiling and CommandLine (Part II)

Reprinted from: http://www.cnblogs.com/roverland/p/3168909.html

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use