Discover browser developer tools

Every modern web browser includes a powerful suite of developer tools. These tools do a range of things, from inspecting currently-loaded HTML, CSS and JavaScript to showing which assets the page has requested and how long they took to load. This article explains how to use the basic functions of your browser‘s devtools.

Note: Before you run through the examples below, open the Beginner‘s example sitethat we built during the Getting started with the Web article series. You should have this open as you follow the steps below.

How to open the devtools in your browser

The devtools live inside your browser in a subwindow that looks roughly like this:

How do you pull it up? Three ways:

  • Keyboard. Ctrl + Shift + I, except

    • Internet Explorer. F12
    • Mac OS X. ? + ? + I
  • Menu bar.
    • Firefox. Menu  ? Toggle Tools, or Tools ? Web Developer ? Toggle Tools
    • Chrome. View ? Developer ? Developer Tools
    • Safari. Develop ? Show Web Inspector. If you can‘t see the Develop menu, go toSafari ? Preferences ? Advanced, and check the Show Develop menu in menu barcheckbox.
    • OperaDeveloper ? Web Inspector
  • Context menu. Press-and-hold/right-click an item on a webpage (Ctrl-click on the Mac), and choose Inspect Element from the context menu that appears. (An added bonus: this method straight-away highlights the code of the element you right-clicked.)

The Inspector: DOM explorer and CSS editor

The devtools usually open by default to the inspector, which looks something like the below screenshot. This tool allows you to see what the HTML on your page looks like at runtime, as well as what CSS is applied to each element on the page. It also allows you to instantly modify the HTML and CSS and see the results of your changes reflected live in the browser viewport.

If you don‘t see the inspector,

  • Tap/click the Inspector tab.
  • In Internet Explorer, tap/click DOM Explorer, or press Ctrl + 1.
  • In Safari, the controls are not so clearly presented, but you should see the HTML if you haven‘t selected something else to appear in the window. Press the Style button to see the CSS.

Exploring the DOM inspector

For a start, try right-clicking (Ctrl-clicking) an HTML element in the DOM inspector and look at the context menu. The menu options vary among browsers, but the important ones are mostly the same:

  • Delete Node (sometimes Delete Element). Deletes the current element.
  • Edit as HTML (sometimes Add attribute/Edit text). Lets you change the HTML and see the results on the fly. Very useful for debugging and testing.
  • :hover/:active/:focus. Forces element states to be toggled on, so you can see what their styling would look like.
  • Copy/Copy as HTML. Copy the currently selected HTML.
  • Some browsers also have Copy CSS Path and Copy XPath available, to allow you to copy the CSS selector or XPath expression that would select the current HTML element.

Try editing some of your DOM now. Double-click an element, or right-click it and chooseEdit as HTML from the context menu. You can make any changes you‘d like, but you cannot save your changes.

Exploring the CSS editor

By default, the CSS editor displays the CSS rules applied to the currently selected element:

These features are especially handy:

  • The rules applied to the current element are shown in order of most-to-least-specific.
  • Click the checkboxes next to each declaration to see what would happen if you removed the declaration.
  • Click the little arrow next to each shorthand property to show the property‘s longhand equivalents.
  • Click a property name or value to bring up a text box, where you can key in a new value to get a live preview of a style change.
  • Next to each rule is the file name and line number the rule is defined in. Clicking that rule causes the dev tools to jump to show it in its own view, where it can generally be edited and saved.
  • You can also click the closing curly brace of any rule to bring up a text box on a new line, where you can write a completely new declaration for your page.

You‘ll notice a number of clickable tabs at the top of the CSS Viewer:

  • Computed: This shows the computed styles for the currently selected element (the final, normalized values that the browser applies).
  • Box model: This represents visually the current element‘s box model, so you can see at a glance what padding, border and margin is applied to it, and how big its content is.
  • Fonts: In Firefox, the Fonts tab shows the fonts applied to the current element.

Find out more

Find more out about the Inspector in different browsers:

The JavaScript console

The JavaScript console is an incredibly useful tool for debugging JavaScript that isn‘t working as expected. It allows you to run lines of JavaScript against the page currently loaded in the browser, and reports the errors encountered as the browser tries to execute your code. To access the console in any browser, just press the Console button. (In Internet Explorer, press Ctrl + 2.) This will give you a window like the following:

To see what happens, try entering the following snippets of code into the console one by one (and then pressing Enter):

  1. alert(‘hello!‘);
    
    document.querySelector(‘html‘).style.backgroundColor = ‘purple‘;
    
    var myImage = document.createElement(‘img‘);
    myImage.setAttribute(‘src‘,‘https://farm4.staticflickr.com/3455/3372925208_e1f2aae4e3_b.jpg‘);
    document.querySelector(‘h1‘).appendChild(myImage);
    

      

  2.  

Now try entering the following incorrect versions of the code and see what you get.

  1. alert(‘hello!);
    
    document.cheeseSelector(‘html‘).style.backgroundColor = ‘purple‘;
    
    var myImage = document.createElement(‘img‘);
    myBanana.setAttribute(‘src‘,‘https://farm4.staticflickr.com/3455/3372925208_e1f2aae4e3_b.jpg‘);
    document.querySelector(‘h1‘).appendChild(myImage);
    

      

  2.  

You‘ll start to see the kind of errors that the browser returns. Often these errors are fairly cryptic, but it should be pretty simple to figure these problems out!

Find out more

Find more out about the JavaScript console in different browsers:

时间: 2024-10-13 00:29:51

Discover browser developer tools的相关文章

ODAC with Oracle Developer Tools for Visual Studio

c#开发Oracle数据库的时候,需要本机没有安装过 Oracle 客户端,直接下载 ODAC with Oracle Developer Tools for Visual Studio工具安装即可 安装包里面包含了最重要的两样: 1.Oracle Instant Client 12.1.0.2.0 2.Oracle Data Provider for .NET 在安装这个工具的时候,会将所有的EF所需要的环境都设置好.

Stop “developer tools access needs to take control of another process for debugging to continue” Alert

There's a much simpler solution for this. Try running the following command: sudo /usr/sbin/DevToolsSecurity --enable   Stop "developer tools access needs to take control of another process for debugging to continue" Alert,布布扣,bubuko.com

Office Developer Tools for Visual Studio 2012现在可用了

[原文发表地址]   Now Available: Office Developer Tools for Visual Studio 2012 正如我以前写过的,我们正在为构建下一代Office和 SharePoint 应用程序而开发工具.这些工具表现为一种在线体验,即熟知的" Napa ",我们一直在每周的基础上更新它,同时它们也作为一个对Visual Studio 丰富客户端的完整扩展集.继上周宣布新的 Microsoft Office 365 的商业可用性的火热之后,我兴奋地宣布

Phalcon 开发工具(Phalcon Developer Tools)

Phalcon提供的这个开发工具主要是用来辅助开发,比方生成一些程序的基本框架.生成控制器模型等. 使用这个工具我们仅仅须要一个简单的命令就可以生成应用的基本框架. 很重要: 要使用这个工具我们必需要安装Phalcon 0.5版本号以上的扩展才行. 这里我们推荐使用PHP5.3.6或更高版本号的PHP. 假设你喜欢使用web版而非console版本号的程序,那么在这里 blog post 能够看到很多其它的内容. 下载(Download)? 我们能够从 Github 上下载或克隆下来这个跨平台的

eclipse中jsp文档无语法着色,安装Eclipse Java Web Developer Tools插件

一.安装Eclipse Java Web Developer Tools插件 1.eclipse菜单:help/install New Software,打开Available Software窗体: 2.Available Software窗体:Work with下拉框中选择mars - http://download.eclipse.org/releases/mars项,mars是eclipse版本,可能有所不同: 3.待Pending...完成后,会显示可选装的插件列表,如果不勾选Cont

chrome developer tools 的一個 bug

我10月12進入新公司,到現在已經半個月了. 這家公司主要是做移動互聯網產品的,非常適合我,每天都能見識到新東西. 今年五六月份,在好易調試代碼時,發現chrome存在一個莫名其妙的問題,總是毫無緣故地刷新網頁.這個問題後來沒有找到原因,不了了之.這週在新公司調試代碼,又發現chrome的developer tools存在一個bug,並且找出了重現的condition. 1 function loop(){ 2 for(var key in undefined){ //we add a brea

Phalcon Developer Tools

本文节选自<Netkiller PHP 手札> http://netkiller.github.io/php/index.html 8.4.1.4. Phalcon Developer Tools # pear channel-discover pear.phalconphp.com # pear install phalcon/Devtools 运行 phalcon 测试是否正确安装 # phalcon Phalcon DevTools (2.0.7) Help:   Lists the c

Google Chrome Developer Tools

原文:https://www.oschina.net/p/chromedevtools Google发布了Google Chrome Developer Tools,这是一系列面向Chrome开发者的工具包. Google Chrome Developer Tools使用BSD授权开源发布,由SDK和Debugger两部分组成.SDK提供了通过TCP/IP协议与Chrome通讯的Java API.而Debugger是一个Eclipse的插件,使用者可以通过Debugger在Eclipse IDE

Enabling Chrome Developer Tools inside Postman

Chrome's Developer Tools are an indispensable part of the modern web development workflow. However, accessing them inside the Postman packaged app takes a few steps. To enable them: Type chrome://flags inside your Chrome URL windowSearch for "packed&