1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
---
title: DOM Inspector 入門
slug: Introduction_to_DOM_Inspector
---
<p>DOM Inspector はブラウザの <strong>Tools > Web Development</strong> メニューからアクセスできる Mozilla のアプリケーションです。これはウェブ開発者が <a href="/en/DOM" title="en/DOM">DOM</a> 全体を見たり、必要なら手動で DOM を更新したりできるようにします。</p>
<div class="note"><strong>注意:</strong> Firefox 3 以降、DOM Inspector はデフォルトインストールには含まれなくなりました。替わりに、Mozilla add-ons サイトから <a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/6622" title="https://addons.mozilla.org/en-US/firefox/addon/6622">ダウンロードしてインストールする</a> 必要があります。</div>
<p>DOM Inspector を最初に起動すると、Mozilla ブラウザに似た2ペインのアプリケーションウィンドウが開きます。ブラウザのように DOM Inspector は URL バー、サイドバー(左ペイン)、メニューを持ち、<strong>Window</strong> や <strong>Tools</strong> メニューは Mail や Chatzilla やその他の小さな拡張機能やダイアログのようなブラウザスイートのメインアプリケーションへのアクセスを提供します。</p>
<p><img align="none" alt="empty DOM Inspector" class=" internal" src="/@api/deki/files/177/=Di_empty.gif"></p>
<h2 id="Starting_the_DOM_Inspector" name="Starting_the_DOM_Inspector">DOM Inspector を開始する</h2>
<p>DOM Inspector の利用を開始するには、以下の3つのうちのひとつを行います:</p>
<h3 id="File_.3E_Inspect_a_Window_.3E" name="File_.3E_Inspect_a_Window_.3E">File > Inspect a Window ></h3>
<p><strong>Inspect a Window</strong> メニュー項目の右に表示されているサブメニューは現在ロードされている DOM ウィンドウのリストです。おそらくブラウザウィンドウと DOM Inspector はすでに開かれており、このリストに表示されます。DOM Inspector は — DOM として認識される — 開かれているすべてのウィンドウを追跡します。そのため、DOM Inspector で特定のウィンドウの DOM にアクセスするには、単に DOM Inspector アプリケーションの中で動的に更新されるリストからウィンドウを選択するだけです。例えば、Mail ウィンドウの DOM を調べるには、Mail を開き、DOM Inspector に戻って <strong>File > Inspect a Window > Inbox for <a class=" link-mailto" href="mailto:yourname@yourdomain.com" rel="freelink">yourname@yourdomain.com</a></strong> を選択します。</p>
<p><img align="none" alt="" class=" internal" src="/@api/deki/files/179/=Di_menu.gif"></p>
<h3 id="File_.3E_Inspect_a_URL..." name="File_.3E_Inspect_a_URL...">File > Inspect a URL...</h3>
<p>URL から任意のウェブページの DOM を調べることが出来ます。この二つ目のメニューアイテムを使用して URL を入力し、DOM Inspector にページの DOM をロードします。アプリケーションそのもののドキュメントオブジェクトモデルを表示するウィンドウの DOM とは対照的に、この "文書" の DOM は最上位の <HTML> タグから始まるウェブページの構造を示します。このメニュー項目を使うには、例えば、<strong>www.brownhen.com</strong> を入力すると brownhen のインデックスページの DOM を見ることが出来ます。</p>
<p><img align="none" alt="DOM of a Web Page" class=" internal" src="/@api/deki/files/43/=Bh_dom.gif"></p>
<h3 id="Ctrl_.2B_Shift_.2B_I_key_shortcut" name="Ctrl_.2B_Shift_.2B_I_key_shortcut"><code><strong>Ctrl + Shift + I</strong></code> キーショートカット</h3>
<p>最後に、<code>Ctrl + Shift + I</code> ショートカットキーは現在ロードしているページの DOM で DOM Inspector を開始します。例えば、Mozilla で www.cnn.com ウェブサイトを読んでいてこのキーをタイプすると、DOM Inspector はページの DOM をロードしその構造を Inspector アプリケーションウィンドウに表示します。</p>
<p>DOM Inspector が DOM をロードすると、左ペインに DOM の構造化された階層ビューを、右ペインに選択したノードの情報(属性とその値など)を表示します。</p>
<p>加えて、ウェブページの DOM を表示している間、DOM Inspector の下半分にウェブページが表示されます。</p>
<p><img align="none" alt="" class="internal" src="/@api/deki/files/43/=Bh_dom.gif"></p>
<p>これは DOM Inspector を独立したブラウザウィンドウを持つことなく利用することが可能になり、選択したノードが DOM Inspector によりページ内でハイライト表示されるのを見るのが容易になります。(最近の Firefox 版では DOM Inspector ウィンドウ内でのウェブページ表示は行われずに、Firefox 内でハイライト表示されます。) <img align="none" alt="DOM Loaded in DI" class="internal" src="/@api/deki/files/183/=Di_small.gif"></p><h2 id="Using_the_DOM_Inspector" name="Using_the_DOM_Inspector">Using the DOM Inspector</h2>
<p>Once you have the DOM of the page or chrome you are interested in, you can use the tree view in the left pane of the DOM Inspector to find and inspect aspects of that DOM you are interested in. One of the biggest and most immediate advantages that this brings to your web and application development is that it makes it possible to <em>find</em> the markup and the nodes in which the interesting parts of a page or a piece of the user interface are defined. One common use of the DOM Inspector is to find the name and location of particular icon being used in the user interface, which is not an easy task otherwise. As you select parts of the DOM in the left pane of the DOM Inspector, the rendered versions of those nodes are highlighted in the user interface itself. <img align="none" alt="" class=" internal" src="/@api/deki/files/182/=Di_select.gif"> If you inspect the main browser window, for example, and select nodes in the right pane (other than the endless list of <code>script</code> elements that are loaded into <code>navigator.xul</code> and that have no visible UI), you will see the various parts of the browser interface being highlighted with a blinking red border. You can traverse the structure and go from largest parts (e.g., the <code>statusbar</code> element that sits at the top-level of the navigator DOM) to smallest parts, such as the "mini-mail" icon that lets users access the Mail application from the bottom left corner of the browser window. <img align="none" alt="" class=" internal" src="/@api/deki/files/180/=Di_mini_mail.gif"></p>
<h3 id="DOM_Inspector_Information_Types" name="DOM_Inspector_Information_Types">DOM Inspector Information Types</h3>
<p>When you have selected a node like the "mini-mail" node, you can select any one of several <em>types</em> of information to display about that node in the right pane of the DOM Inspector application window, all of which are available from the pull-down menu in the upper left corner of the right pane. <img align="none" alt="" class=" internal" src="/@api/deki/files/184/=Di_types.gif"> In order to find out what the actual name of the file is being used to provide the small mail icon, you can select <strong>CSS Style Rules</strong> from this menu and see the various selectors and rules that have been applied for those selectors. The rule that applies the mail icon to the "mini-mail" element is ID-based (since the icon is unique to the mail item in the taskbar), and uses a <code>list-style-image</code> property to point to a file in the theme JAR. That file turns out to be a GIF located at: <code><a class=" external" rel="freelink">chrome://commmunicator/skin/taskbar/mail.gif</a></code>. The list of types available from this pull-down menu gives you some idea about how extensive the DOM Inspector's inspecting capabilities are. The following table provides an overview of what these sets of information are about:</p>
<blockquote>
<table> <tbody> <tr> <td><strong>DOM Node</strong></td> <td>The default view. DOM Node shows the structural DOM representation of the given page or chrome.</td> </tr> <tr> <td><strong>Box Model</strong></td> <td>The box model is the layout system of Mozilla's application interface. <code>box</code> elements <p>use stretchiness, flexibility, and nesting to achieve table-like layout capabilities in XUL documents. This view shows how boxes and these layout attributes are used to position elements within the interface.</p> </td> </tr> <tr> <td><strong>XBL Bindings</strong></td> <td>XBL is a language that allows you to build extensions in XUL and HTML. Where XBL <em>bindings</em> <p>are loaded into documents by means of CSS rules, this view lets you inspect them.</p> </td> </tr> <tr> <td><strong>CSS Style Rules</strong></td> <td>This view shows you all of the CSS rules that are applied to the selected nodes.</td> </tr> <tr> <td><strong>Computed Style</strong></td> <td> <p>The computed style of an element is all of the style rules that get applied to that element, whether from explicit style declarations, from script, or from inheritance. The computed style view of an element's style rules gives you a long, flat list of rules that you can inspect and {{ mediawiki.external('#update update') }} if you wish.</p> </td> </tr> <tr> <td><strong>JavaScript Object</strong></td> <td>This view shows you all of the JavaScript objects that are used to script and manipulate a given <p>node. Common examples of JavaScript objects are <code>target</code> objects that are used to trap and get information about events fired in the interface.</p> </td> </tr> </tbody>
</table>
</blockquote>
<h3 id="Selecting_Elements_in_a_User_Interface" name="Selecting_Elements_in_a_User_Interface">Selecting Elements in a User Interface</h3>
<p>Another powerful interactive feature of the DOM Inspector is that it can display the subtree of any element in any DOM it has loaded. In other words, when you have the DOM Inspector open and have enabled this functionality by choosing <strong>Search > Select Element by Click</strong> or by clicking the little magnifying glass icon in the upper left portion of the DOM Inspector application, you can click anywhere in a loaded web page or the chrome of the Mozilla application interface, and the element you click will be threaded into the left pane and information about it displayed in the right.</p>
<h3 id="Searching_for_Nodes_in_the_DOM" name="Searching_for_Nodes_in_the_DOM">Searching for Nodes in the DOM</h3>
<p>Another way to inspect the DOM is to search for particular elements you're interested in by ID, class, or attribute. When you select <strong>Search > Find Nodes...</strong> or press <code>Ctrl + F</code>, the DOM Inspector displays a find dialog that lets you find elements in various ways, and that gives you incremental searching by way of the <code><F3></code> shortcut key. <img align="none" alt="" class=" internal" src="/@api/deki/files/181/=Di_search.gif"></p>
<h3 id="Updating_the_DOM_Dynamically" name="Updating_the_DOM_Dynamically">Updating the DOM Dynamically</h3>
<p>A final feature to mention in this introduction is the ability is the ability the DOM Inspector gives you to dynamically update information reflected in the DOM about web pages, user interface, and other elements. Note that when the DOM Inspector displays information about a particular node or subtree, it presents individual nodes and their values (in the DOM, attributes are subnodes of elements, typically) in an active, sortable list. You can right-click individual items in this list and be presented with a context menu that lets you <em>edit</em> the values of those attributes. <img align="none" alt="" class=" internal" src="/@api/deki/files/176/=Di_edit.gif"> For example, <code>table</code> elements are often used to layout elements in a web page, but when something goes wrong it can be difficult to find the offending cell, especially when tables are nested several deep, as they often are on complicated web pages. You can use this dynamic editig capability of the DOM Inspector to set tables aside (i.e., by changing their background color, adding a border, and so on). This interactivity allows you to shrink and grow element size, change icons, and do other layout-tweaking updates—all without actually changing the DOM as it is defined in the file on disk.</p>
<h2 id="Loving_the_Inspector" name="Loving_the_Inspector">Loving the Inspector</h2>
<p>The DOM Inspector can take some figuring out, but once you get used to it, you may find that these structured views of web pages and interfaces were exactly the aspects of your own application development that were missing. The DOM Inspector not only presents all this information about pages in a clear and structured way, it gives you way to find and update those structures, and it's simple to access via shortcuts and menus already available in the Mozilla browser. Used in concert with Mozilla tools like <a class="external" href="http://www.mozilla.org/projects/venkman">Venkman</a>, the JavaScript debugger, the DOM Inspector can give you a <em>complete</em> view of any web page or DOM-based application interface. It's become an ordinary tool in my own web page development and even my normal browsing—where I see a page that looks like it's been put together in some interesting way and I hit <code>Ctrl + Shift + I</code> to look at the DOM of the page, interesting CSS rules the author has used to present the page, or other, sometimes hidden information about that document.</p>
<p>{{ languages( { "en": "en/Introduction_to_DOM_Inspector"} ) }}</p>
|