12 firebug skills for Web developers

Source: Internet
Author: User

I believe that many developers engaged in Web development have heard and used firebug, but most people may not know it yet. In fact, it is a powerful editor in web design, it can comprehensively track and debug HTML, Dom, CSS, HTTP, and JavaScript. It is a plug-in of the Firefox browser. Therefore, it is recommended that web developers make full use of the Firefox browser and the firebug plug-in for daily debugging. This article selects the primary use skills of firebug that should be mastered by 12 web developers and introduces them to you.

1. Use firebug to find any content on the page

I wonder if you have ever encountered such a situation. In a complicated HTML page, when you want to find the actual HTML corresponding to a page element, you haveCodeIs very troublesome. With firebug, you only need to right-click an element on the page and select "view element" in the pop-up menu ", the code corresponding to this element will be found in the HTML page code immediately, which is very convenient, as shown in:

Similarly, a faster method is provided: you only need to focus on the arrow at the top left of the firebug plug-in, as shown in. When you move the cursor over the page, in the firebug console, the code of the HTML element that passes through the mobile operation is immediately displayed:

2. You can use firebug to modify HTML and CSS.

With firebug, you can directly modify HTML, add HTML attributes, delete elements, add CSS styles, and implement more functions, such:

You can clearly see in the menu that you can perform various modification operations on HTML elements by clicking the code in the HTML section and right-clicking the code to perform operations in the pop-up menu.

3. You can use firebug to view DOM elements and operate on XML.

When you open an HTML page and use firebug to view HTML code, you can also click the DOM tree in the control panel to view the entire HTML structure in the DOM tree structure. If you open an XML file, right-click any element in the XML file and choose to perform relevant operations on the XML file in the pop-up menu, for example:

4. Use firebug to debug JavaScript code

In the firebug console, to debug JavaScript code, you only need to start the script control panel and then click the console button, in the drop-down list, select javascipt and HTML errors (you can also choose to display more errors). Then, the arrow >>> appears at the bottom. Here, you can enter the javascipt code. after entering the code, immediately press the Enter key to execute the code, which is very convenient, such:

One tips is that you can also use the tab key to automatically complete the reminder function when you enter javascipt. For example, for a long javascipt function, when you do not finish entering the key, you only need to press the tab key firebug to automatically complete the configuration.

5. After loading the page multiple times, firebug will remember the location before loading

No matter how many times you reload the page, firebug always remembers the position of the page before loading every time it loads the page (for example, if you have browsed the bottom of the page, then load the page again, after the new page is loaded, you are still taken to the bottom of the page ).

6. Use the $ tag to facilitate variable access

In the above 4th, we mentioned that JavaScript debugging can be performed under >>>, another trick is to use $1 to access the last variable that has been accessed, and so on. You can use $2 to access the second and last variables that have been accessed. For example:

7. firebug will display the modified content with High Brightness

In firebug, as long as you have modified the content on the page, the modified content will be displayed in yellow with high brightness, such:

8. Monitor JavaScript Running Performance

In firebug, you can click the "Profile" option in the console. This will enable the firebug performance monitoring function, and then you can perform a series of operations on the page, after you click the Profile button again, the performance monitoring activity will be stopped. Then, firebug will display a list of functions and the number of calls involved in the operation, the time used, average time, minimum time, and maximum time are shown in:

9. Powerful network data monitoring function of firebug

Firebug also provides powerful network data monitoring functions. Developers often observe various HTTP requests and responses when developing Web applications. In this regard, firebug is very powerful. First, you only need to enable the network function in the control panel, and then each time you run the page, you can clearly see the details of each HTTP request and HTTP response. For example:

In, you only need to click the plus sign next to each request to view the specific details of the request, such:

You can see the various information in the HTTP header. Similarly, if you want to view the information of the elements such as the ratio, Flash, and so on the current page, you can also click different tabs to filter and view the information, which is very convenient.

10. Use the log function of firebug

When designing a page, you often need to record some information on the next page. At this time, you can use the log function in firebug to output some information to the firebug console, this facilitates debugging. Firebug provides a console object that is registered to the Javascript runtime environment when the plug-in is loaded.Program. The console object provides a log method, for example:

1234567 <Script language = "JavaScript" type = "text/JavaScript"> console. log ('this is log message'); console. debug ('this is debug message'); console. error ('this is error message'); console.info ('this is info message'); console. warn ('this is warning message'); </SCRIPT>

Execute the following code in Firefox and the following information appears in the firebug console:

As you can see, each level of log output has a color icon, which can give users a very eye-catching reminder. At the same time, the console. log also supports formatting string output. You can use a syntax similar to printf in C language to call this function: console. log ("% s is % d years old. "," Bob ", 42 ).

11. You can debug the program in firebug.

In the Javascript control panel of the firebug console, You can debug the JavaScript on the page. The method is very simple. You only need to click on the left of the line to be debugged, and a breakpoint will appear, remember the following common shortcut keys:

(1) F10 enters the next line;

(2) Continue debugging with F8;

(3) F11 is used to debug the function body in JavaScript;

(4) Shift + F11 jump out of the function body.

12. You can set conditional breakpoints in firebug.

In firebug, you can also set breakpoints with conditional judgment, such:

Summary

Firefox and firebug are both powerful in Web programming. This article only describes some of these techniques, for more information, see the official firebug website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.