diff options
Diffstat (limited to 'files/zh-cn/archive/web_标准')
4 files changed, 0 insertions, 724 deletions
diff --git a/files/zh-cn/archive/web_标准/index.html b/files/zh-cn/archive/web_标准/index.html deleted file mode 100644 index 19024fa1eb..0000000000 --- a/files/zh-cn/archive/web_标准/index.html +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: Web 标准 -slug: Archive/Web_标准 -translation_of: Archive/Web_Standards ---- -<div> - <strong>Web标准</strong> Web标准经过精心设计,旨在让广大用户享有最佳的上网体验,同时也确保在网上发布的文件经久不衰。由这些标准设计、构建的网站简化并降低了开发成本,同时又可以让更多人访问,并适应更多的上网设备。随着传统桌面浏览器的进化、新型互联网设备进入市场,经由这些准则开发的网站将继续正常运作。 <sup><a href="https://developer.mozilla.org/zh-CN/docs/Archive/Web_%E6%A0%87%E5%87%86#endnote_1">[1]</a></sup></div> -<table class="topicpage-table"> - <tbody> - <tr> - <td> - <h4 id="Documentation" name="Documentation"><a href="/Special:Tags?tag=Web_Standards&language=en" title="Special:Tags?tag=Web_Standards&language=en">参考文章</a></h4> - <dl> - <dt> - <a href="/en/Migrate_apps_from_Internet_Explorer_to_Mozilla" title="en/Migrate_apps_from_Internet_Explorer_to_Mozilla">将应用从IE浏览器迁移到Mozilla浏览器</a></dt> - <dd> - <small>是否在迁移针对IE浏览器定制的应用到Mozilla浏览器时遇到了麻烦?本文涵盖了迁移应用到开源的基于Mozilla的浏览器的过程中相关的常见问题。</small></dd> - <dt> - <a href="/en/Using_Web_Standards_in_your_Web_Pages" title="en/Using_Web_Standards_in_your_Web_Pages">在您的网页中应用Web标准</a></dt> - <dd> - <small>本文概述了如何升级你的网页从而使之遵循 W3C Web标准。</small></dd> - <dt> - <a href="/en/Choosing_Standards_Compliance_Over_Proprietary_Practices" title="en/Choosing_Standards_Compliance_Over_Proprietary_Practices">为什么选择符合标准而不是私有实现?</a></dt> - <dd> - <small>应用通常是跨多个开发小组设计的,因此在开发过程中需要一个通用标准。</small></dd> - <dt> - <a href="/en/The_Business_Benefits_of_Web_Standards" title="en/The_Business_Benefits_of_Web_Standards">Web标准的商业价值</a></dt> - <dd> - <small>本文探讨了遵守Web标准、丢弃私有标记和技术是如何帮助一家公司实现其商业目标的。</small></dd> - </dl> - <p><span class="alllinks"><a href="/Special:Tags?tag=Web_Standards&language=en" title="Special:Tags?tag=Web_Standards&language=en">查看全部...</a></span></p> - </td> - <td> - <h4 id="Community" name="Community">社区</h4> - <ul> - <li>浏览 Mozilla 论坛...</li> - </ul> - <p></p><ul> - <li><a href="https://lists.mozilla.org/listinfo/dev-web-development"> 邮件列表</a></li> - - - <li><a href="http://groups.google.com/group/mozilla.dev.web-development"> 新闻组</a></li> - <li><a href="http://groups.google.com/group/mozilla.dev.web-development/feeds"> Web feed</a></li> -</ul><p></p> - <ul> - <li><a class="external" href="http://webstandards.org/">The Web Standards Project</a></li> - <li><a class="external" href="http://webdevfeedhouse.com/">WebDev FeedHouse</a></li> - <li><a href="/en/Web_Standards/Community" title="en/Web_Standards/Community">Other community links...</a></li> - </ul> - <h4 id="Tools" name="Tools">工具</h4> - <ul> - <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug 扩展</a></li> - <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/60">Web Developer 扩展 </a></li> - <li><a class="external" href="http://validator.w3.org/">W3C 标记验证服务</a></li> - <li><a class="external" href="http://jigsaw.w3.org/css-validator/">W3C CSS 验证服务</a></li> - </ul> - <p><span class="alllinks"><a href="/Special:Tags?tag=Web_Standards:Tools&language=en" title="Special:Tags?tag=Web_Standards:Tools&language=en">查看全部...</a></span></p> - <h4 id="Examples" name="Examples">Examples</h4> - <ul> - <li><a class="external" href="http://www.mozilla.org/newlayout/demo/">Gecko Demos</a></li> - <li><a class="external" href="http://www.csszengarden.com/">css 禅意花园</a></li> - <li><a class="external" href="http://www.meyerweb.com/eric/css/edge/">Eric Meyers's css/edge</a></li> - <li><a class="external" href="http://dmoz.org/Computers/Programming/Languages/JavaScript/W3C_DOM/Demos/">W3C DOM Demos</a></li> - </ul> - <h4 id="Related_Topics" name="Related_Topics">Related Topics</h4> - <dl> - <dd> - <a href="/en/CSS" title="en/CSS">CSS</a>, <a href="/en/DHTML" title="en/DHTML">DHTML</a>, <a href="/en/HTML" title="en/HTML">HTML</a>, <a href="/en/Web_Development" title="en/Web_Development">Web 开发</a>, <a href="/en/XHTML" title="en/XHTML">XHTML</a>, <a href="/en/XML" title="en/XML">XML</a></dd> - </dl> - </td> - </tr> - </tbody> -</table> -<hr> -<p><small><span id="endnote_1"><strong><a href="https://developer.mozilla.org/zh-CN/docs/Archive/Web_%E6%A0%87%E5%87%86#ref_1">^</a></strong></span> - <a class="external" href="http://webstandards.org/">The Web Standards Project</a></small></p> -<p></p> diff --git a/files/zh-cn/archive/web_标准/issues_arising_from_arbitrary-element_hover/index.html b/files/zh-cn/archive/web_标准/issues_arising_from_arbitrary-element_hover/index.html deleted file mode 100644 index c63ee0cc9e..0000000000 --- a/files/zh-cn/archive/web_标准/issues_arising_from_arbitrary-element_hover/index.html +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: 发行任意元素的hover的起因 -slug: Archive/Web_标准/Issues_Arising_From_Arbitrary-Element_hover -tags: - - CSS - - 所有分类 -translation_of: Archive/Web_Standards/Issues_Arising_From_Arbitrary-Element_hover ---- -<p> </p> -<p><span class="comment">Summary: Thanks to long-standing limitations, we're used to thinking of hover styles as applying only to hyperlinks, which has led to some sloppy authoring practices that are now causing problems for some Web sites. This technote explains the source of the problems and how to avoid encountering them.</span> 很多设计者都使用CSS2伪类<code>:hover</code>装饰他们的链接。这个创新,首先被Microsoft® Internet Explorer引入,随后被CSS规范所采用,是非常受欢迎的文本链接样式,尤其是那些看起来和动起来像以JavaScript驱动的交互动态效果。除了推进浏览器对CSS的支持以外,还产生了一些出乎意料的hovering地活泼行为在一些页面。</p> -<h3 id="Hover.E5.92.8C.E9.9D.9E.E9.93.BE.E6.8E.A5.E5.85.83.E7.B4.A0" name="Hover.E5.92.8C.E9.9D.9E.E9.93.BE.E6.8E.A5.E5.85.83.E7.B4.A0">Hover和非链接元素</h3> -<p><a class="external" href="http://www.w3.org/TR/CSS2/selector.html#x36">Section 5.11.3 of CSS2</a>定义了三个动态的伪类(<code>:hover</code>, <code>:active</code>, and <code>:focus</code>),然后继续表示:</p> -<blockquote> - CSS可能不会定义以上那几个状态的元素,或者状态为什么被加入的左派。脚本能否改变产生用户事件的元素,或者不同的设置和使用不同方法的指向以及活动的元素。(翻译的可能不准确,不明白可以看下原文。)</blockquote> -<p>这样,尽管设计者们习惯于过去的想法,将这些状态被应用在专有的超链接上,但它们不是那样有限在CSS2中。理论上任何元素都能达到这三种状态,和基于这样状态的样式。这不是传统上的使用情形。</p> -<h3 id=".E6.9C.AA.E6.8C.87.E5.AE.9A.E7.9A.84.E4.BC.AA.E7.B1.BB" name=".E6.9C.AA.E6.8C.87.E5.AE.9A.E7.9A.84.E4.BC.AA.E7.B1.BB">未指定的伪类</h3> -<p>第二篇的问题来自当我们在一个选择器上考虑使用未指定的伪类的效果时。例如:</p> -<pre>:hover {color: red;}</pre> -<p>这样等效于CSS2的标准:</p> -<pre>*:hover {color: red;}</pre> -<p>哪一个都被解释为“设置任何元素的hover前景色为红色。”所以,段落、表格、标题也在hover范围内,在一个页面中任何其它元素的文本将变成红色。</p> -<p>一个公用未指定的类和伪类的hover一起使用的变量,像这样:</p> -<pre>.nav:hover {color: red;}</pre> -<p>在这种情况,只有实例的<code>class</code>属性的值是<code>nav</code>位置的超链接时候,才能正常工作。无论如何,这种类型的规则经常看见在像这样的联合标记中:</p> -<pre><td class="nav"> -<a href="one.html" class="nav">one</a> | -<a href="two.html" class="nav">two</a> | -<a href="thr.html" class="nav">three</a> | -<a href="fou.html" class="nav">four</a> -</td></pre> -<p>因为装入的表格有一个<code>class</code>的值是<code>nav</code>,所以当用户的鼠标移动到那个单元里面,竖线字符将会变成红色。链接将会在它们hover的时候变成红色。</p> -<h3 id="Gecko.E7.9A.84.E8.A1.8C.E4.B8.BA" name="Gecko.E7.9A.84.E8.A1.8C.E4.B8.BA">Gecko的行为</h3> -<p>在基于Netscape Gecko的20020410(Netscape 6.1+)版本后构建的浏览器中,<code>:hover</code>样式可应用于页面中的任意标签。这样设计者们可以使用未限定的伪类,或者使用未限定的类伪类的这种结合,这样做会出现可见的hover样式的应用会多于它们应有链接的危险。最可靠的解决方法是为选择器添加一个锚元素,像这样:</p> -<pre>a:hover {color: red;} -a.nav:hover {color: red;}</pre> -<p>在基于Mozilla 1.0和更新版本(Netscape 7+)的浏览器中包含试图消除老文档遗留的问题的代码。如果页面运行在“转换显示”模式中,未限定的伪类将受限制只能用于链接。在基于Mozilla 1.3b及更新版本构建的浏览器中,这个转换显示被延伸包括了选择器,关于<code>:hover</code>伪类结合一个未限定的类选择器(详细资料可以查看Bugzilla上的#169078条目)。</p> -<h3 id=".E5.91.BD.E5.90.8D.E9.94.9A.E8.AE.B0.E7.9A.84.E9.97.AE.E9.A2.98" name=".E5.91.BD.E5.90.8D.E9.94.9A.E8.AE.B0.E7.9A.84.E9.97.AE.E9.A2.98">命名锚记的问题</h3> -<p>除了先前的描述效果之外,有两个其它的相关公共效果可能不是设计者期待的。其中一个被确认容易固定,但另一个有一些微妙。</p> -<p>首先,这个问题是设计者打开一个指定的锚记,但它没有关闭。例如:</p> -<pre><a name="pagetop"> -<h2>My Page</h2></pre> -<p>没有a <code></a></code>,这个锚记将在整个文档中有效。这样通常的意思是将获取页面中的hover样式。考虑到以下规则的效果:</p> -<pre>a:hover {color: red;}</pre> -<p>在一个文档中有一个未关闭的锚记,那么任何文本的样式将是设计者打开标记的前景颜色(除非其它CSS规则干涉)。</p> -<p>这里提出的第二个公用问题,哪一个锚记能接受hover样式。虽然,设计者们可能打算把选择器<code>a:hover</code>只应用于超链接,它也将应用于锚记,因为选择器只是规定所有的<code>a</code>元素应用哪一个hover样式。为了消除这个问题,设计者应该使用混合的伪类语法来描述CSS2:</p> -<pre>a:link:hover {color: red;} -a:visited:hover {color: maroon;}</pre> -<p>注意像这样的语法,问题是当它们hover时,visit和未visit时链接不同。以<code>a:hover</code>为基础时这不是一个问题。当然,这个选择器<code>a:link:hover</code>将只应用于未visit的链接,所以设计者需要一样的样式同时应用于visit和未visit的链接,应该组织把2个选择器放在单一的规则中。</p> -<h3 id=".E6.8E.A8.E8.8D.90" name=".E6.8E.A8.E8.8D.90">推荐</h3> -<p>为了避免未预料的问题,设计者们被鼓励在打算用于超链接的动态伪类中包含元素名,以提高<b>健壮性</b>。此外,混合伪类要预防hover样式被用于非链接的锚。因此,以a:hover的基础为首选<code>a:hover</code>应该总是代替刚才的<code>:hover</code>和<code>a:link:hover</code>(和<code>a:visited:hover</code>)。</p> -<h3 id=".E7.9B.B8.E5.85.B3.E9.93.BE.E6.8E.A5" name=".E7.9B.B8.E5.85.B3.E9.93.BE.E6.8E.A5">相关链接</h3> -<ul> - <li><a class="external" href="http://www.w3.org/TR/CSS2/selector.html#x36">The dynamic pseudo-classes: :hover, :active, and :focus</a></li> -</ul> -<div class="originaldocinfo"> - <h3 id=".E6.96.87.E7.AB.A0.E5.8E.9F.E5.A7.8B.E4.BF.A1.E6.81.AF" name=".E6.96.87.E7.AB.A0.E5.8E.9F.E5.A7.8B.E4.BF.A1.E6.81.AF">文章原始信息</h3> - <ul> - <li>作者: Eric A. Meyer, Netscape Communications</li> - <li>最后更新: Published 07 Mar 2003; Revised 21 Mar 2003</li> - <li>版权信息: Copyright © 2001-2003 Netscape. All rights reserved.</li> - <li>注意: This reprinted article was originally part of the DevEdge site.</li> - </ul> -</div> -<p> </p> diff --git a/files/zh-cn/archive/web_标准/rdf_in_mozilla_faq/index.html b/files/zh-cn/archive/web_标准/rdf_in_mozilla_faq/index.html deleted file mode 100644 index d6df231e2d..0000000000 --- a/files/zh-cn/archive/web_标准/rdf_in_mozilla_faq/index.html +++ /dev/null @@ -1,320 +0,0 @@ ---- -title: RDF 问题集 -slug: Archive/Web_标准/RDF_in_Mozilla_FAQ -tags: - - RDF -translation_of: Archive/Web_Standards/RDF_in_Mozilla_FAQ ---- -<p> </p> -<h2 id="General" name="General">General</h2> -<h3 id="Where_do_I_start.3F" name="Where_do_I_start.3F">Where do I start?</h3> -<p><a href="cn/RDF">RDF</a> serves two primary purposes in Mozilla. First, it is a simple, cross-platform database for small data stores. Second, and more importantly, the RDF model is used along with <a href="cn/XUL/Template_Guide">XUL templates</a> as an abstract "API" for displaying information. <a href="cn/RDF_in_Fifty_Words_or_Less">RDF in Fifty Words or Less</a> is a quick, high-level description of what RDF does in Mozilla. The <a href="cn/RDF_Back-end_Architecture_(external)">RDF Back-end Architecture</a> document describes in more detail how Mozilla's RDF implementation works, and gives a quick overview of the interfaces that are involved.</p> -<h3 id="Where_do_I_find_information_on_Open_Directory_.28.22dmoz.22.29.3F" name="Where_do_I_find_information_on_Open_Directory_.28.22dmoz.22.29.3F">Where do I find information on Open Directory ("dmoz")?</h3> -<p>Unfortunately, <em>not here</em>! Well, here's a little... Start at <a class="external" href="http://www.dmoz.org/" rel="freelink">http://www.dmoz.org/</a> for more information on the Open Directory. The Open Directory dataset is available as a (huge) RDF/XML dump. It describes thousands of Web sites using a mix of the <a class="external" href="http://www.dublincore.org/">Dublin Core</a> metadata vocabulary and the DMoz taxonomy. See <a class="external" href="http://dmoz.org/rdf.html">their RDF pages</a> for more information, or <a class="external" href="http://groups.yahoo.com/group/odp-rdf-announce/">odp-rdf-announce</a> for updates relating to their exact data format. The <a class="external" href="http://chefmoz.org/">ChefMoz</a> site (collaborative restaurant guide) is also <a class="external" href="http://chefmoz.org/rdf.html">available in RDF</a>.</p> -<p>If you have problems with the DMoz and ChefMoz data, it's best to contact those projects directly. But if you do something interesting with this content (eg. have Mozilla use it, eg. by loading chunks of it into a XUL UI from a remote site), don't forget to let <a class="link-mailto" href="mailto:mozilla-rdf@mozilla.org">mozilla-rdf</a> and the <a class="link-mailto" href="mailto:www-rdf-interest@w3.org">RDF Interest Group</a> lists know. Those lists would probably also be interested in tools for cleaning / re-processing / storing the DMoz data too. See the <a class="external" href="http://dmoz.org/Computers/Internet/Searching/Directories/Open_Directory_Project/Use_of_ODP_Data/">sites using ODP data</a> pages for some directories based on the ODP RDF dumps.</p> -<h3 id="What_is_a_datasource.3F" name="What_is_a_datasource.3F">What is a datasource?</h3> -<p>RDF can generally be viewed in two ways: either as a graph with nodes and arcs, or as a "soup" of logical statements. A datasource is a subgraph (or collection of statements, depending on your viewpoint) that are for some reason collected together. Some examples of datasources that exist today are "browser bookmarks", "browser global history", "IMAP mail accounts", "NNTP news servers", and "RDF/XML files".</p> -<p>In Mozilla, datasources can be <em>composed</em> together using the <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFCompositeDataSource.idl">composite data source</a>. This is like overlaying graphs, or merging collections of statements ("microtheories") together. Statements about the same RDF <em>resource</em> can then be intermingled: for example, the "last visit date" of a particular website comes from the "browser global history" datasource, and the "shortcut keyword" that you can type to reach that website comes from the "browser bookmarks" datasource. Both datasources refer to "website" by URL: this is the "key" that allows the datasources to be "merged" effectively.</p> -<p>For a more detailed account of how to <em>write</em> a datasource, refer to the <a href="cn/RDF_Datasource_How-To">RDF Datasource How-To</a>.</p> -<h3 id="How_does_Mozilla_manage_datasources.3F" name="How_does_Mozilla_manage_datasources.3F">How does Mozilla manage datasources?</h3> -<p>The <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFService.idl">RDF service</a> manages a table of all loaded datasources. The table is keyed by the datasource's "URI", which is either the URL of an RDF/XML file, or a "special" URI starting with <code>rdf:</code> that refers to a built-in datasource.</p> -<p>Datasources may be loaded via the RDF service using the <code>GetDataSource()</code> method. If the URI argument refers to an RDF/XML file's URL, then the RDF service will create an <em>RDF/XML datasource</em> and asynchronously parse it. The datasource will remain "cached" until the last reference to the datasource is released.</p> -<p>If the URI argument refers to a built-in datasource, the RDF service will use the XPCOM <em>Component Manager</em> to load a component whose <em>ContractID</em> is constructed using the "special" URI and the well-known <a class="link-mailto" href="mailto:prefix@mozilla.org" rel="freelink">prefix@mozilla.org</a>/rdf/datasource;1?name=</code>.</p> -<p>For example,</p> -<pre class="eval">rdf:foo -</pre> -<p>Would load:</p> -<pre class="eval">@mozilla.org/rdf/datasource;1?name=foo -</pre> -<p>As with RDF/XML datasources, a datasource that is retrieved this way is "cached" by the RDF service until the last reference is dropped.</p> -<h3 id="How_do_I_create_a_datasource_from_an_RDF.2FXML_file.3F" name="How_do_I_create_a_datasource_from_an_RDF.2FXML_file.3F">How do I create a datasource from an RDF/XML file?</h3> -<p>You can either create an RDF/XML datasource using the <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFService.idl">RDF service</a>'s <code>GetDataSource()</code> method:</p> -<pre class="eval"><span class="highlightblue">// Get the RDF service</span> -var RDF = - Components - .classes["@mozilla.org/rdf/rdf-service;1"] - .getService(Components.interfaces.nsIRDFService); -<span class="highlightblue">// ...and from it, get the datasource. Make sure that your web server -// dishes it up as <b>text/xml</b> (recommended) or <b>text/rdf</b>!</span> -var ds = RDF.GetDataSource("<a class="external" href="http://www.mozilla.org/some-rdf-file.rdf" rel="freelink">http://www.mozilla.org/some-rdf-file.rdf</a>"); -<span class="highlightblue">// Note that <b>ds</b> will load asynchronously, so assertions will not -// be immediately available</span> -</pre> -<p>Alternatively, you can create one directly using the XPCOM Component Manager, as the following code fragment illustrates:</p> -<pre class="eval"><span class="highlightblue">// Create an RDF/XML datasource using the XPCOM Component Manager</span> -var ds = - Components - .classes["@mozilla.org/rdf/datasource;1?name=xml-datasource"] - .createInstance(Components.interfaces.nsIRDFDataSource); -<span class="highlightblue">// The <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFRemoteDataSource.idl">nsIRDFRemoteDataSource</a> interface has the interfaces -// that we need to setup the datasource.</span> -var remote = - ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); -<span class="highlightblue">// Be sure that your web server will deliver this as <b>text/xml</b> (recommended) or <b>text/rdf</b>!</span> -remote.Init("<a class="external" href="http://www.mozilla.org/some-rdf-file.rdf" rel="freelink">http://www.mozilla.org/some-rdf-file.rdf</a>"); -<span class="highlightblue">// Make it load! Note that this will happen asynchronously. By setting -// <b>aBlocking</b> to true, we could force it to be synchronous, but this -// is generally a bad idea, because your UI will completely lock up!</span> -remote.Refresh(false); -<span class="highlightblue">// Note that <b>ds</b> will load asynchronously, so assertions will not -// be immediately available</span> -</pre> -<p>You may decide that you need to "manually" create an RDF/XML datasource if you want to force it to load synchronously.</p> -<h3 id="How_do_I_reload_an_RDF.2FXML_datasource.3F" name="How_do_I_reload_an_RDF.2FXML_datasource.3F">How do I reload an RDF/XML datasource?</h3> -<p>You can force an RDF/XML datasource (or any datasource that supports <a class="external" href="http://lxr.mozilla.org/mozilla/source/source/rdf/base/idl/nsIRDFRemoteDataSource.idl"><code>nsIRDFRemoteDataSource</code></a>) using <code>Refresh()</code> method of <code>nsIRDFRemoteDataSource</code>. <code>Refresh()</code> takes a single parameter that indicates whether you'd like it to perform its operation synchronously ("blocking") or asynchrounously ("non-blocking"). You should <em>never</em> do a synchronous load unless you <em>really</em> know what you're doing: this will freeze the UI until the load completes!</p> -<h3 id="How_can_I_tell_if_an_RDF.2FXML_datasource_has_loaded.3F" name="How_can_I_tell_if_an_RDF.2FXML_datasource_has_loaded.3F">How can I tell if an RDF/XML datasource has loaded?</h3> -<p>Using the <a class="external" href="http://lxr.mozilla.org/mozilla/source/source/rdf/base/idl/nsIRDFRemoteDataSource.idl"><code>nsIRDFRemoteDataSource</code></a> interface, it is possible to immediately query the <code>loaded</code> property to determine if the datasource has loaded or not:</p> -<pre class="eval"><span class="highlightblue">// Get the RDF service</span> -var RDF = - Components - .classes["@mozilla.org/rdf/rdf-service;1"] - .getService(Components.interfaces.nsIRDFService); -<span class="highlightblue">// Get the datasource.</span> -var ds = RDF.GetDataSource("<a class="external" href="http://www.mozilla.org/some-rdf-file.rdf" rel="freelink">http://www.mozilla.org/some-rdf-file.rdf</a>"); -<span class="highlightblue">// Now see if it's loaded or not...</span> -var remote = - ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); - -if (remote.loaded) { - alert("the datasource was already loaded!"); -} -else { - alert("the datasource wasn't loaded, but it's loading now!"); -} -</pre> -<p>Say the datasource <em>wasn't</em> loaded, and is loading asynchronously. Using this API and JavaScript's <code>setTimeout()</code>, one could set up a <em>polling loop</em> that would continually check the <code>loaded</code> property. This is kludgy, and even worse, won't detect a <em>failed</em> load, for example, if there wasn't any data at the URL!</p> -<p>For this reason, there is an <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFXMLSink.idl">observer interface</a> that allows you to spy on a datasource's progress. The following code illustrates its usage:</p> -<pre class="eval"><span class="highlightblue">// This is the object that will observe the RDF/XML load's progress</span> -var Observer = { - onBeginLoad: function(aSink) - {}, - - onInterrupt: function(aSink) - {}, - - onResume: function(aSink) - {}, - - onEndLoad: function(aSink) - { alert("done!"); }, - - onError: function(aSink, aStatus, aErrorMsg) - { alert("error! " + aErrorMsg); } -}; -<span class="highlightblue">// Get the RDF service</span> -var RDF = - Components - .classes["@mozilla.org/rdf/rdf-service;1"] - .getService(Components.interfaces.nsIRDFService); -<span class="highlightblue">// Get the datasource.</span> -var ds = RDF.GetDataSource("<a class="external" href="http://www.mozilla.org/some-rdf-file.rdf" rel="freelink">http://www.mozilla.org/some-rdf-file.rdf</a>"); -<span class="highlightblue">// Now see if it's loaded or not...</span> -var remote = - ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); - -if (remote.loaded) { - alert("the datasource was already loaded!"); -} -else { - alert("the datasource wasn't loaded, but it's loading now!"); - <span class="highlightblue">// RDF/XML Datasources are all <b>nsIRDFXMLSink</b>s</span> - var sink = - ds.QueryInterface(Components.interfaces.nsIRDFXMLSink); - <span class="highlightblue">// Attach the observer to the datasource-as-sink</span> - sink.addXMLSinkObserver(Observer); - <span class="highlightblue">// Now <b>Observer'</b>s methods will be called-back as - // the load progresses.</span> -} -</pre> -<p>Note that the observer will remain attached to the RDF/XML datasource unless <code>removeXMLSinkObserver</code> is called.</p> -<h3 id="How_do_I_access_the_information_in_a_datasource.3F" name="How_do_I_access_the_information_in_a_datasource.3F">How do I access the information in a datasource?</h3> -<p>The <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFDataSource.idl"><code>nsIRDFDataSource</code></a> interface is the means by which you access and manipulate the assertions in a datasource.</p> -<ul> - <li><code>boolean HasAssertion(aSource, aProperty, aTarget, aTruthValue)</code>.<br> - This tests the datasource to see if it has the specified tuple.</li> - <li><code>nsIRDFNode GetTarget(aSource, aProperty, aTruthValue)</code>.</li> - <li><code>nsISimpleEnumerator GetTargets(aSource, aProperty, aTruthValue)</code>.</li> - <li><code>nsIRDFResource GetSource(aProperty, aTarget, aTruthValue)</code>.</li> - <li><code>nsISimpleEnumerator GetSources(aProperty, aTarget, aTruthValue)</code>.</li> - <li><code>nsISimpleEnumerator ArcLabelsIn(aTarget)</code>.</li> - <li><code>nsISimpleEnumerator ArcLabelsOut(aSource)</code>.</li> -</ul> -<p>You can also use the <a href="#How_do_I_manipulate_RDF_.22containers.22.3F">RDF container</a> interfaces to access information contained in RDF <em>containers</em>.</p> -<h3 id="How_do_I_change_information_in_the_datasource.3F" name="How_do_I_change_information_in_the_datasource.3F">How do I change information in the datasource?</h3> -<p>To use 'Assert' to add one assertion and 'Unassert' to remove one. Refer to <a class="external" href="http://www.mozilla.org/rdf/back-end-architecture.html">Mozilla RDF Back end Architecture</a></p> -<pre class="eval">ds.Assert(homepage, FV_quality, value, true); -ds.Unassert(homepage, FV_quality, value, true); -</pre> -<h3 id="How_do_I_save_changes_to_an_RDF.2FXML_datasource_back.3F" name="How_do_I_save_changes_to_an_RDF.2FXML_datasource_back.3F">How do I save changes to an RDF/XML datasource back?</h3> -<p>An RDF/XML datasource can be <code>QueryInterface()</code>'d to <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFRemoteDataSource.idl"><code>nsIRDFRemoteDataSource</code></a>. This interface has a <code>Flush()</code> method, which will attempt to write the contents of the datasource back to the URL from which they were loaded, using a protocol specific mechanism (e.g., a <code>file:</code> URL just writes the file; an <code>http:</code> URL might do an HTTP-POST). <code>Flush()</code> only writes the datasource if its contents have changed.</p> -<h3 id="How_do_I_merge_two_or_more_datasources_to_view_them_as_one.3F" name="How_do_I_merge_two_or_more_datasources_to_view_them_as_one.3F">How do I merge two or more datasources to view them as one?</h3> -<p>Use nsIRDFCompositeDataSource. This interface is derived from nsIRDFDataSource. An implementation of this interface will typically combine the statements from several datasources together as a collective. Because the nsIRDFCompositeDataSource interface is derived from nsIRDFDataSource, it can be queried and modified just like an individual data source.</p> -<h3 id="How_do_I_access_.22built-in.22_datasources.3F" name="How_do_I_access_.22built-in.22_datasources.3F">How do I access "built-in" datasources?</h3> -<p>A <em>built-in datasource</em> is a locally-installed component that implements <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFDataSource.idl">nsIRDFDataSource</a>. For example, the <a class="external" href="http://lxr.mozilla.org/mozilla/source/xpfe/components/bookmarks/src/nsBookmarksService.cpp">bookmarks service</a>. First, check <a href="#What_is_the_security_model_for_RDF.2FXML_in_XUL.3F">here</a> to make sure you will be <em>allowed</em> to access a built-in datasource. There are several security restrictions on accessing built-in datasources from "untrusted" XUL and JS.</p> -<p>Since a built-in datasource is just an XPCOM component, you can instantiate it directly using the XPConnect component manager.</p> -<pre class="eval">// Use the component manager to get the bookmarks service -<span class="highlightgreen">var bookmarks = - Components. - classes["@mozilla.org/rdf/datasource;1?name=bookmarks"]. - getService(Components.interfaces.nsIRDFDataSource);</span> - -// Now do something interesting with it... -if (bookmarks.HasAssertion( - RDF.GetResource("<a class="external" href="http://home.netscape.com/NC-rdf#BookmarksRoot" rel="freelink">http://home.netscape.com/NC-rdf#BookmarksRoot</a>"), - RDF.GetResource("<a class="external" href="http://home.netscape.com/NC-rdf#child" rel="freelink">http://home.netscape.com/NC-rdf#child</a>"), - RDF.GetResource("<a class="external" href="http://home.netscape.com/NC-rdf#PersonalToolbarFolder" rel="freelink">http://home.netscape.com/NC-rdf#PersonalToolbarFolder</a>"), - true) { - // ... -} -</pre> -<p>Alternatively, some datasources have "special" RDF-friendly ContractIDs that make it easy to instantiate the datasource using either the <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFService.idl"><code>nsIRDFSerivce</code></a>'s <code>GetDataSource()</code> method or the <code>datasources</code> attribute on a XUL template. These ContractIDs are of the form</p> -<pre class="eval">@mozilla.org/rdf/datasource;1?name=<i>name</i> -</pre> -<p>And are accessable via <code>GetDataSource()</code> and the <code>datasources</code> attribute using the shorthand <code>rdf: - <i> - name</i> - </code>. For example, the following XUL fragment illustrates how to add the bookmarks service as a datasource into a XUL template.</p> -<pre class="eval"><tree datasources="rdf:bookmarks"> - ... -</tree> -</pre> -<h3 id="How_do_I_manipulate_RDF_.22containers.22.3F" name="How_do_I_manipulate_RDF_.22containers.22.3F">How do I manipulate RDF "containers"?</h3> -<p>To manipulate an RDF "container" (an <code><rdf:Seq></code>, for example), you can use <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFContainerUtils.idl"><code>nsIRDFContainerUtils</code></a> which can be instantiated as a service with the following ContractID:</p> -<pre class="eval">@mozilla.org/rdf/container-utils;1 -</pre> -<p>You can use this service to detect if something is an RDF container using <code>IsSeq()</code>, <code>IsBag()</code>, and <code>IsAlt()</code>. You can "make a resource into a container" if it isn't one already using <code>MakeSeq()</code>, <code>MakeBag()</code>, or <code>MakeAlt()</code>. These methods return an <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFContainer.idl"><code>nsIRDFContainer</code></a> which allows you to do container-like operations without getting your hands too dirty.</p> -<p>Alternatively, if your datasource already has an object that <em>is</em> an RDF container, you can instantiate an <code>nsIRDFContainer</code> object with the</p> -<pre class="eval">@mozilla.org/rdf/container;1 -</pre> -<p>ContractID and <code>Init()</code> it with the datasource and resource as parameters. Note that this will fail if the resource isn't already a container.</p> -<h2 id="XUL_Templates" name="XUL_Templates">XUL Templates</h2> -<p>XUL templates are created by specifying a <code>datsources</code> attribute on an element in a XUL document.</p> -<p>There are two "forms" that XUL templates may be written in. The "simple" form, which is currently the most common form in the Mozilla codebase, and the "extended" form, which allows for sophisticated pattern matching against the RDF graph. See the <a href="cn/XUL/Template_Guide">XUL:Template Guide</a>. (These are bizarrely arranged because the <em>eventual</em> intent is to introduce templates using the extended form -- which in many ways is conceptually simpler, even if more verbose -- and then treat the "simple" form as a shorthand for the extended form.)</p> -<h3 id="What_can_I_build_with_a_XUL_template.3F" name="What_can_I_build_with_a_XUL_template.3F">What can I build with a XUL template?</h3> -<p>You can build <em>any</em> kind of content using a XUL template. You may use any kind of tag (including HTML, or arbitrary XML) in the <code><action></code> section of a <code><rule></code>.</p> -<h3 id="When_should_I_use_a_XUL_template.3F" name="When_should_I_use_a_XUL_template.3F">When should I use a XUL template?</h3> -<p>One alternative to using RDF and XUL templates is to use the <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/">W3C DOM APIs</a> to build up and manipulate a XUL (or HTML) content model. There are times, however, when doing so may be inconvenient:</p> -<ol> - <li><em>There are several "views" of the data</em>. For example, Mozilla mail/news reveals the folder hierarchy in the toolbar, the "folder pane", in several menus, and in some of the dialogs. Rather than writing three pieces of JS (or C++) code to construct the DOM trees each for <code><menubutton></code>, <code><menu></code>, and <code><tree></code> content models, you write three compact sets of rules for each content model.</li> - <li><em>The data can change</em>. For example, a mail/news user may add or remove IMAP folders. (Note how this requirement complicates the task of building a content model!) The XUL template builder uses the rules to automatically keep <em>all</em> content models in sync with your changes.</li> -</ol> -<p>In order to take advantage of this functionality, you must of course be able to express your information in terms of the <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFDataSource.idl">RDF datasource API</a>, either by using the built-in <em>memory datasource</em>, using RDF/XML to store your information, or writing your own implementation (possibly in JavaScript) of <code>nsIRDFDataSource</code>.</p> -<h3 id="What_gets_loaded_when_I_specify_.22datasources.3D.22" name="What_gets_loaded_when_I_specify_.22datasources.3D.22">What gets loaded when I specify "datasources="</h3> -<p>The <code>datasources</code> attribute on the "root" of a template specifies a whitespace-separated list of <em>datasource URIs</em> to load. But what is a "datasource URI"? It is either:</p> -<ul> - <li>An abbreviated ContractID for a locally installed component. By specifying <code>rdf: - <i> - name</i> - </code>, you instruct the template builder to load the XPCOM component with the ContractID <code>@mozilla.org/rdf/datasource;1?name= - <i> - name</i> - </code>.</li> - <li>The URL of an RDF/XML file. For example, - <pre>file:///tmp/foo.rdf -chrome://mycomponent/content/component-data.rdf -http://www.mysite.com/generate-rdf.cgi -ftp://ftp.somewhere.org/toc.rdf -</pre> - <p>The load will be processed <em>asynchronously</em>, and as RDF/XML arrives, the template builder will generate content.</p> - </li> -</ul> -<p>In either case, the datasource will be loaded using the <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFService.idl"><code>nsIRDFService</code></a>'s <code>GetDataSource()</code> method, so it will be <a href="#How_does_Mozilla_manage_datasources.3F">managed</a> similarly to all other datasources loaded this way.</p> -<h3 id="What_is_the_security_model_for_RDF.2FXML_in_XUL.3F" name="What_is_the_security_model_for_RDF.2FXML_in_XUL.3F">What is the security model for RDF/XML in XUL?</h3> -<p>XUL that is loaded from a "trusted" URL (currently, any <code>chrome:</code> URL) can specify <em>any</em> datasource URI in the <code>datasources</code> attribute of the XUL template.</p> -<p>XUL that is loaded from an "untrusted" URL can only specify an RDF/XML document from the same <em>codebase</em> (in the Java sense of the word) that the XUL document originated from. No "special" (i.e., <code>rdf:</code>) datasources may be loaded from untrusted XUL.</p> -<h3 id="How_do_I_add_a_datasource_to_a_XUL_template.3F" name="How_do_I_add_a_datasource_to_a_XUL_template.3F">How do I add a datasource to a XUL template?</h3> -<p>Although it's possible to create a XUL template with an "implicit" set of datasources by specifying the <code>datasources</code> attribute, there are often times when you won't know the datasource that you want to add until <em>after</em> the XUL is loaded. For example, your XUL may need compute the datasources that it wants to display in an <code>onload</code> handler. Or, it may need to add a datasource later based on some user action.</p> -<p>Here's a simple example that illustrates how to do this. Let's start with the following XUL.</p> -<pre class="eval"><window xmlns="<a class="external" href="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" rel="freelink">http://www.mozilla.org/keymaster/gat...re.is.only.xul</a>"> - ... - <span class="highlightgreen"><tree id="my-tree" datasources="rdf:null"> - ... - </tree></span> - ... -</window> -</pre> -<p>Assuming that we've aquired a datasource somehow (e.g., like <a href="#How_do_I_create_a_datasource_from_an_RDF.2FXML_file.3F">this</a>), the following sample code illustrates how to <em>add</em> that datasource to the template, and then force the template to rebuild itself based on the newly added datasource's contents.</p> -<pre class="eval">var ds = <span class="highlightblue">/* assume we got this somehow! */</span>; -<span class="highlightblue">// Get the DOM element for 'my-tree'</span> -var tree = document.getElementById('my-tree'); -<span class="highlightblue">// Add our datasource to it</span> -tree.database.AddDataSource(ds); -<span class="highlightblue">// Force the tree to rebuild *now*. You have to do this "manually"!</span> -tree.builder.rebuild(); -</pre> -<p>Any XUL element with a <code>datasources</code> attribute will "get" a <code>database</code> property and a <code>builder</code> property. The <code>database</code> property refers to an <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIRDFCompositeDataSource.idl"><code>nsIRDFCompositeDataSource</code></a> object, which is contains the datasources from which the template is built.</p> -<p>The <code>builder</code> property refers to an <a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/base/idl/nsIXULTemplateBuilder.idl"><code>nsIXULTemplateBuilder</code></a> object, which is a the "builder" that maintains the state of the template's contents.</p> -<p>Note the <code>rdf:null</code> datasource: this is a special datasource that says, "hey, I don't have a datasource for you yet, but I'm going to add one later, so set yourself up for it!" It causes the <code>database</code> and <code>builder</code> properties to get installed, but leaves the <code>database</code> empty of datasources: you've got to add these in yourself!</p> -<h3 id="Can_I_manipulate_a_XUL_template_using_the_DOM_APIs.3F" name="Can_I_manipulate_a_XUL_template_using_the_DOM_APIs.3F">Can I manipulate a XUL template using the DOM APIs?</h3> -<p>Yes: you can add rules, remove rules, change a rule's conditions, and change the content that is built by a rule. In fact, you can change <em>anything</em> about a template using the <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/">W3C DOM APIs</a>.</p> -<p>The only caveat is that you must call <code>rebuild()</code> before the changes you've made will take effect (just as you must if you <a href="#How_do_I_add_a_datasource_to_a_XUL_template.3F">add a datasource</a> to the XUL template).</p> -<h3 id="How_do_I_insert_plaintext_from_a_template.3F" name="How_do_I_insert_plaintext_from_a_template.3F">How do I insert plaintext from a template?</h3> -<p>To insert plaintext in a template, use the <code><text></code> element.</p> -<pre class="eval"><template> - <rule> - <conditions>...</condition> - <bindings>...</bindings> - <action> - <span class="highlightgreen"><text value="?some-variable" /></span> - </action> - </rule> -</template> -</pre> -<p>The above template will create a content model that runs a series of text nodes together.</p> -<h2 id="Troubleshooting" name="Troubleshooting">Troubleshooting</h2> -<p>Tricks and tips from the field.</p> -<h3 id="My_RDF.2FXML_file_won.27t_load." name="My_RDF.2FXML_file_won.27t_load.">My RDF/XML file won't load.</h3> -<p>The most common cause for RDF/XML not to load from a web server is incorrect MIME type. Make sure your server is delivering the file as <code>text/xml</code> (recommended) or <code>text/rdf</code> (bogus).</p> -<p>Note that the W3C RDF Core WG are registering application/rdf+xml, though this isn't understood by any Mozilla code yet. (do we have a bug registered to track this? -- <a class="link-mailto" href="mailto:danbri-mozilla@rdfweb.org">danbri</a>)</p> -<p>Another possible problem: for remotely-loaded XUL and RDF, you might need to adjust Mozilla's security restrictions (see belowfor example code). If XUL isn't loading your RDF, and the mimetype is OK, this could well be your problem.</p> -<p>You can use the <code>rdfcat</code> and <code>rdfpoll</code> utilities to verify that the RDF/XML is actually valid. Both of these programs are built by default on Windows, and on Linux when the <code>configure --enable-tests</code> is specified.</p> -<ul> - <li><code><a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/tests/rdfcat/rdfcat.cpp">rdfcat</a> - <i> - url</i> - </code><br> - Takes as a parameter a URL from which to read an RDF/XML file, and will "cat" the file back to the console. You can use it to verify that the RDF/XML that you've written is being properly parsed by Mozilla.</li> - <li><code><a class="external" href="http://lxr.mozilla.org/mozilla/source/rdf/tests/rdfpoll/rdfpoll.cpp">rdfpoll</a> - <i> - url</i> - [ - <i> - interval</i> - ]</code><br> - Takes as a parameter a URL from which to read an RDF/XML file. It also accepts an optional <em>poll interval</em>, where it will re-load the URL. It outputs the assertions that are generated from each load. Note that a polling reload generates a set of <em>differences</em> between the current and previous contents of the RDF/XML file. This is useful for debugging generated RDF/XML that may change over time.</li> -</ul> -<p>Both these programs are slow to load and run (but they <em>will</em> run, eventually). They initialize XPCOM and bring up Necko to be able to load and process URLs just like Mozilla does.</p> -<h3 id="Nothing_happens_after_I_call_AddDataSource." name="Nothing_happens_after_I_call_AddDataSource.">Nothing happens after I call AddDataSource.</h3> -<p>Note that the template builder will <em>not</em> rebuild the contents of a template automatically after <code>AddDataSource</code> or <code>RemoveDataSource</code> have been called on the builder's <code>database</code>. To refresh the template's contents, you must manually call <code> - <i> - elt.</i> - builder.rebuild()</code> yourself.</p> -<p>Why? This was done to avoid multiple rebuilds when more than one datasource is added to the <code>database</code>.</p> -<h2 id="Examples" name="Examples">Examples</h2> -<h3 id="Where_can_I_find_some_.28working.29_examples.3F" name="Where_can_I_find_some_.28working.29_examples.3F">Where can I find some (working) examples?</h3> -<p>A few examples are posted <a class="external" href="http://www.mozilla.org/rdf/doc/examples.html">here</a>. Some of these are included in signed scripts, and are runnable from HTTP directly.</p> -<p>See also <a class="link-https" href="https://bugzilla.mozilla.org/data/duplicates.rdf"><code>duplicates.rdf</code></a> (for live RDF feed from Mozilla) alongside <a class="link-https" href="https://bugzilla.mozilla.org/duplicates.xul"><code>duplicates.xul</code></a>. Note that for these to work, you have to relax Mozilla's <a href="cn/Bypassing_Security_Restrictions_and_Signing_Code">security model</a>. To do this, add the following line to your preferences file. (Shut down Mozilla first since it overwrites your preferences file when you quit.)</p> -<pre class="eval">user_pref("signed.applets.codebase_principal_support", true); -</pre> -<p>Mozilla will ask you if you want to grant the scripts in <code>duplicates.xul</code> permission to access XPConnect; respond in the affirmative.</p> -<p>Currently, Mozilla does not allow unprivileged access to the RDF interfaces and services; see bug <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=122846">122846</a> for details.</p> -<p>Please mail <a class="external" href="http://rdfweb.org/people/danbri/">danbri</a>, mozilla-rdf or waterson with URLs if you are aware of other examples to which we ought to link!</p> -<h2 id="Notes" name="Notes">Notes</h2> -<ol> - <li>See also <a class="external" href="http://www.w3.org/RDF/">W3C RDF</a> and <a class="external" href="http://www.w3.org/2001/sw/">Semantic Web</a> pages for more information on RDF and related technologies.</li> -</ol> -<h2 id="Contributors" name="Contributors">Contributors</h2> -<ul> - <li>Examples section added 2002-07-02 by <a class="external" href="http://rdfweb.org/people/danbri/">danbri</a> </li></li> - <li>Thanks to Myk Melez for notes on remote XUL / security policy</li> -</ul> -<p>Author: <a class="link-mailto" href="mailto:waterson@netscape.com">Chris Waterson</a></p> -<div class="originaldocinfo"> - <h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2> - <ul> - <li>Author(s): <a class="link-mailto" href="mailto:waterson@netscape.com">Chris Waterson</a></li> - <li>Last Updated Date: December 22, 2004</li> - <li>Copyright Information: Copyright (C) <a class="link-mailto" href="mailto:waterson@netscape.com">Chris Waterson</a></li> - </ul> -</div> -<p></p> diff --git a/files/zh-cn/archive/web_标准/using_the_right_markup_to_invoke_plugins/index.html b/files/zh-cn/archive/web_标准/using_the_right_markup_to_invoke_plugins/index.html deleted file mode 100644 index 2642ff72b1..0000000000 --- a/files/zh-cn/archive/web_标准/using_the_right_markup_to_invoke_plugins/index.html +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: 用正确的标识来调用插件 -slug: Archive/Web_标准/Using_the_Right_Markup_to_Invoke_Plugins -tags: - - HTML - - Plugins - - 全部分类 -translation_of: Archive/Web_Standards/Using_the_Right_Markup_to_Invoke_Plugins ---- -<p><small>这篇文章介绍怎样使用正确的HTML来调用插件.讨论了对象元素及其嵌入元素,以及在网页中使用恰当的HTML来调用Java的细节.</small></p> - -<h3 id="The_Object_Element:_W3C_Standards_and_Cross-Browser_Issues" name="The_Object_Element:_W3C_Standards_and_Cross-Browser_Issues">对象元素 Object Element: W3C标准及跨浏览器问题</h3> - -<p>对象元素是HTML 4.01规范的一部分, 是被推荐的调用插件的机制. Its use is subject to a few caveats that this section outlines.</p> - -<p>Traditionally, the object element has been used differently by Microsoft Internet Explorer and by Mozilla-based browsers such as Netscape 7. In IE, the object element is used to invoke a plugin that is built on the ActiveX architecture. Here's an example of this kind of usage for IE:</p> - -<pre><!-- IE ONLY CODE --> -<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" -codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" -width="366" height="142" id="myFlash"> - <param name="movie" value="javascript-to-flash.swf" /> - <param name="quality" value="high" /> - <param name="swliveconnect" value="true" /> -</object> -</pre> - -<p>In the above example, the <code>classid</code> attribute that goes along with the object element points to a "clsid:" URN followed by the Unique Identifier of an ActiveX control (in the above example, the string beginning with "D27..."). This is, in fact, the Unique Identifier of Macromedia's Flash plugin, and developers are expected to know such Unique Identifiers in order to invoke the component of their choice. The <code>codebase</code> attribute used above points to a location that houses the CAB file containing the ActiveX control. In this context, the codebase attribute is used as an <strong>obtainment mechanism</strong> -- that is to say, a way to obtain a control if it isn't present. If the Flash ActiveX control is not installed, IE will then go to the URL referenced by the codebase attribute and retrieve the ActiveX control. Additional <code>param</code> elements (which are "children" of the above object element) specify configuration parameters for the Flash plugin. For instance, the <code>param name="movie"</code> tells the Flash plugin the location of the SWF file to start playing.</p> - -<p>With the release of Netscape 7.1, this kind of ActiveX use of the object element is supported for use with the Microsoft® Windows Media Player. Only the Windows Media Player is supported as an ActiveX control in Netscape 7.1. The details are covered in <a href="/cn/Windows_Media_in_Netscape" title="cn/Windows_Media_in_Netscape">another article</a>.</p> - -<p>Browsers such as Netscape 7 will not render the Flash plugin if the above kind of markup is used, because Netscape 7 does not support ActiveX or ActiveX-based component invocations, with the exception of Windows Media Player in Netscape 7.1. Mozilla-based browsers support the Netscape Plugin architecture, which is not COM based like ActiveX (and thus, not invoked via a Unique Identifier) but rather, MIME type based. Mozilla-based browsers support the use of the object element along with a MIME type. Here is an example of this usage, once again for the Macromedia Flash plugin:</p> - -<pre><object type="application/x-shockwave-flash" data="javascript-to-flash.swf" -width="366" height="142" id="myFlash"> - <param name="movie" value="javascript-to-flash.swf" /> - <param name="quality" value="high" /> - <param name="swliveconnect" value="true" /> - <p>You need Flash -- get the latest version from - <a href= "http://www.macromedia.com/downloads/">here.</a></p> -</object> -</pre> - -<p>In the above example, <code>application/x-shockwave-flash</code> is the Flash MIME type, and will invoke the Netscape-specific Flash architecture in Mozilla-based browsers. The data attribute points to the SWF file to play, and the configuration parameters (the <code>param</code> elements) are used in a consistent manner both for IE and for Mozilla-based browsers such as Netscape 7. In fact, the above usage will also work for IE, which understands MIME type invocations for certain MIME types such as Flash <em>in addition</em> to ActiveX-style <code>classid</code> invocations.</p> - -<p>Since the use of MIME type for Flash will work for both IE and Netscape 7, you can use the above markup to invoke the Flash plugin for both IE and Netscape 7. However, there are a few caveats that developers ought to bear in mind when using the <code>object</code> element with Mozilla-based browsers such as Netscape 7 and in IE:</p> - -<h4 id="Caveats" name="Caveats">Caveats(警告)</h4> - -<ul> - <li>If you use one single object element for both browsers (as in the above example), <strong>it is not possible to provide a cross-browser <em>obtainment mechanism</em> for streamlined download</strong>. You cannot use a <code>codebase</code> attribute to link to a signed CAB file for the ActiveX component, since this won't work in Mozilla-based browsers such as Netscape 7. Furthermore, IE's use of the <code>codebase</code> attribute as an obtainment mechanism itself is not strictly correct according to the HTML 4.01 specification, which says that the <code>codebase</code> attribute should be used to qualify URNs referenced by the <code>data</code>, <code>archive</code>, and <code>classid</code> attributes. Future Netscape browsers based on Mozilla source code will allow the use of a special <code>param</code> element to specify where to get plugins that are not present, but this feature is not available in Netscape 7. This feature is discussed in Mozilla <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=167601" title='FIXED: [object] Support &amp;lt;param name="PLUGINURL" ...>'>bug 167601</a>.</li> -</ul> - -<ul> - <li><strong>IE doesn't display nested</strong> <code>object</code> <strong>elements correctly according to the HTML 4.01 specification</strong>. According to the specification, you can nest elements and browsers should stop if they can display the outermost element, or else keep going inwards till they can find something to display. IE displays everything as if they are in series, and not nested. Thus, in the following example, instead of stopping at the ActiveX control, IE will display the same animation twice since it also understands the MIME type for Flash:</li> -</ul> - -<pre><!-- Usage Will Not Work As Intended --> -<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" -codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" -width="366" height="142" id="myFlash"> - <param name="movie" value="javascript-to-flash.swf" /> - <param name="quality" value="high" /> - <param name="swliveconnect" value="true" /> - - <object type="application/x-shockwave-flash" data="javascript-to-flash.swf" - width="366" height="142" id="myFlashNSCP"> - <param name="movie" value="javascript-to-flash.swf" /> - <param name="quality" value="high" /> - <param name="swliveconnect" value="true" /> - <p>You need Flash -- get the latest version from - <a href="http://www.macromedia.com/downloads/"> - here.</a></p> - </object> - -</object> -</pre> - -<ul> - <li><strong>Web authors have to specify an <em>obtainment mechanism</em> in Mozilla-based browsers -- the browser won't automatically retrieve plugins that are missing if you don't specify where to get the plugin from using the <code>codebase</code> attribute</strong>. If you don't specify a <code>codebase</code> attribute, and the plugin is not installed,the browser will display only the alternate innermost text. It won't attempt to retrieve a missing plugin using the Netscape Plugin Finder service. This behavior is not incorrect according to the HTML 4.01 specification, but it obliges web authors to diligently specify <em>obtainment mechanisms</em>. At a minimum, web authors will have to nest some alternate text inside their object elements telling users where to obtain the missing component. Adding an additional layer of convenience in the form of automatic retrieval is the subject of a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=180411" title="Plugin Finder Service is not invoked for OBJECT element">bug 180411</a> in the Mozilla open source code.</li> -</ul> - -<ul> - <li><strong>Some plugins don't understand all the <code>param</code> elements that their documentation suggests should configure them in Mozilla-based browsers.</strong> An example is versions of the Macromedia Flash player plugin upto Flash Player 6 r. 47, which don't understand the <code><param name="movie" value="animation.swf"></code> param element, which is supposed to tell the Flash player which animation to start playing. In order to work around this, developers are encouraged to use the data attribute to the object element: <code><object type="application/x-shockwave-flash" data="animation.swf"..../></code>. The fact that the Flash player doesn't understand this <code>param</code> is a Macromedia Flash Player bug that is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=180378" title='macromedia.com - Flash ought to support &amp;lt;param name="movie..."> in addition to data attribute'>bug 180378</a>.</li> -</ul> - -<h4 id="Recommendation" name="Recommendation">Recommendation</h4> - -<p>In order to overcome the shortcomings that you can't nest object elements in IE and that there isn't a way you can simply use one <code>object</code> element in a cross-browser way (with architecture specific obtainment mechanisms), the best course of action is to dynamically write <code>object</code> elements based on architecture. For example, on browsers that support ActiveX, such as IE, create an <code>object</code> element with a classid attribute, and on browsers that support the Netscape Plugin architecture, use a MIME type. Here is an example of some JavaScript which does this:</p> - -<pre>if (window.ActiveXObject) -{ - -// browser supports ActiveX -// Create object element with -// download URL for IE OCX - -document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'); -document.write(' codebase="http://download.macromedia.com'); -document.write('/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"'); -document.write(' width="366" height="142" id="myFlash">'); -document.write(' <param name="movie" value="javascript-to-flash.swf" />'); -document.write(' <param name="quality" value="high" />'); -document.write(' <param name="swliveconnect" value="true" />'); -document.write('<\/object>'); - -} - -else -{ - -// browser supports Netscape Plugin API - -document.write('<object id="myFlash" data="javascript-to-flash.swf"'); -document.write(' type="application/x-shockwave-flash"'); -document.write(' width="366" height="142">'); -document.write('<param name="movie" value="javascript-to-flash.swf" />'); -document.write('<param name="quality" value="high" />'); -document.write('<param name="swliveconnect" value="true" />'); -document.write('<p>You need Flash for this.'); -document.write(' Get the latest version from'); -document.write(' <a href="http://www.macromedia.com/downloads">here<\/a>.'); -document.write('<\/p>'); -document.write('<\/object>'); - -} -</pre> - -<p>See also: <a class="external" href="http://www.alistapart.com/articles/flashsatay/">Flash Satay</a></p> - -<h4 id="The_Object_Element_and_Java" name="The_Object_Element_and_Java">The Object Element and Java</h4> - -<p>Mozilla-based browsers such as Netscape 6.x, Netscape 7, and CompuServe 7 ship with the <a class="external" href="http://java.sun.com/j2se/downloads.html">Java plugin that Sun provides</a>. Users installing Netscape 6.x and Netscape 7 have a choice of whether or not to install Java. Unlike Netscape Communicator 4.x, Netscape 6.x and 7 do not have a default Java Virtual Machine -- they rely on Sun's plugin. During the Netscape Communicator 4.x days, Netscape Communications used to develop a Java Virtual Machine which supported Java 1.5.0 and below. Now, with Netscape 6 and 7, the Java Virtual Machine is Sun's plugin. Netscape no longer develops or ships a default Netscape Java Virtual Machine with the browser.</p> - -<p>Sun's Java plugin can be invoked by the <code>object</code> element, just like any other plugin. Once again, IE typically invokes the plugin by way of an <code>object</code> element used in conjunction with a <code>classid</code> attribute that points to an ActiveX Unique Identifier. Each major version of the plugin has a Unique Identifier. For instance, this is an example of the type of markup that will invoke the JRE 1.4.1 in IE, using the unique identifier for the JRE 1.4.1:</p> - -<pre><!-- IE ONLY CODE --> -<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" - width="460" height="160" -codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_1-windows-i586.cab#version=1,4,1"> - <param...> - <param...> -</object> -</pre> - -<p>The above invocation won't work for Mozilla-based browsers such as Netscape 7 because of the same reason mentioned above: <code>classid</code> used in conjunction with a Unique Identifier references an architecture (ActiveX) that Mozilla code (and thus Netscape 7) does not support. You can invoke the Java plugin for Netscape 7 and other Mozilla-based browsers by using the appropriate Java MIME type. Here is an example:</p> - -<pre><object type="application/x-java-applet;jpi-version=1.4.1_01" -width="460" height="160"> - <param name="code" value="Animator.class" /> - <param name="imagesource" value="images/Beans" /> - <param name="backgroundcolor" value="0xc0c0c0" /> - <param name="endimage" value="10" /> - <param name="soundsource" value="audio"> - <param name="soundtrack" value="spacemusic.au" /> - <param name="sounds" value="1.au|2.au|3.au|4.au|5.au|6.au|7.au|8.au|9.au|0.au" /> - <param name="pause" value="200" /> - <p>You need the Java Plugin. - Get it from <a href="http://java.sun.com/products/plugin/index.html">here.</a></p> -</object> -</pre> - -<p>The above code mentions a version specific MIME type, and if the Mozilla-based browser such as Netscape 7 doesn't have JRE 1.4.1_01 installed, the alternate text is displayed. It isn't always necessary to give such a version specific MIME type. If you aren't taking advantage of any version specific features, a more generic MIME type such as <code>application/x-java-vm</code> will do the job just as well. The configuration parameters for the applet, including the class which contains the initial entry point (Animator.class, referenced by the "code" <code>param</code> element), are specified in multiple <code>param</code> elements.</p> - -<p>Mozilla-based browsers such as Netscape 7 also allow for a special classid attribute that can also be used. This is the special "java:" classid. Here is an example using this invocation method:</p> - -<pre><object classid="java:NervousText.class" width="534" height="50"> - <param name="text" value="Java 2 SDK, Standard Edition v1.4" /> - <p>You need the Java Plugin. - Get it from - <a href="http://java.sun.com/products/plugin/index.html">here. - </a> - </p> -</object> -</pre> - -<p>The "java:" <code>classid</code> allows you to reference the class that provides the primary entry point. The rest of the configuration parameters work via the <code>param</code> elements.</p> - -<h4 id="Applet_--_The_Popular_Choice" name="Applet_--_The_Popular_Choice">Applet -- The Popular Choice</h4> - -<p>The <code>applet</code> element is still very much supported, and is the most popular way currently to invoke Java applets. In Netscape 7 and CompuServe 7, the <code>applet</code> element directly invokes the Java plugin. Here is a sample:</p> - -<pre><applet code="NervousText.class" width="534" height="50"> - <param name="text" value="Java(TM) 2 SDK, Standard Edition v1.4" /> -</applet> -</pre> - -<p>The <code>applet</code> element has been deprecated in the HTML 4.01 specification, but an advantage to using it is that in Mozilla-based browsers such as Netscape 7, if you are missing Java, an automatic obtainment mechanism is in place. The browser will use Netscape's Plugin Finder Service to download the missing Java plugin. The <a href="#References">References</a> section gathers resources about the use of the applet element.</p> - -<h4 id="The_Embed_Element" name="The_Embed_Element">The Embed Element</h4> - -<p>The <code>embed</code> element has been used to invoke plugins since the early days of Netscape browsers. Typically, the <code>embed</code> element is nested within an <code>object</code> element, such that the outer <code>object</code> element invokes an ActiveX control for IE, whereas the inner <code>embed</code> element invokes a Netscape Plugin. Here is an example of this usage:</p> - -<pre><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" -codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" -width=366 height=142 id="myFlash"> - <param name="movie" value="javascript_to_flash.swf" /> - <param name="quality" value="high" /> - <param name="swliveconnect" value="true" /> - <embed src="javascript_to_flash.swf" quality="high" width="366" height="142" - type="application/x-shockwave-flash" - pluginspage="http://www.macromedia.com/downloads/" - name="myFlash" swliveconnect="true"> - </embed> -</object> -</pre> - -<p>Links to the rules governing the use of the <code>embed</code> element can be found in the <a href="#References">References</a> section. The <code>embed</code> element is currently the most widely used element to invoke plugins in Netscape browsers. It is important to note, however, that the <code>embed</code> element is not part of the HTML 4.01 Specification, and is therefore not a W3C standard. Some caveats governing the use of the <code>embed</code> element are:</p> - -<ul> - <li>Do not include a <code>name</code> attribute with the <code>object</code> element, especially if it is the same name value as that of the <code>embed</code> element. Though doing so actually violates the HTML 4.01 standard, some code generators give <code>name</code> attributes to the <code>object</code> element. Mozilla-based browsers will not allow you to access the named <code>embed</code> element via JavaScript DOM 0 methods if the <code>object</code> element has the same <code>name</code>. Use the <code>id</code> attribute with the <code>object</code> element. The <code>id</code> attribute of the <code>object</code> element can be the same value as the <code>name</code> attribute of the <code>embed</code> element.</li> - <li>You'll notice that the <code>embed</code> element allows configuration parameters passed to the plugin via custom attributes, such as <code>swliveconnect="true"</code>. These are analogous to the <code>param</code> elements used by the <code>object</code> element. Different plugin vendors may require different configuration paramaters to be passed via the <code>embed</code> element, and learning these is advisable.</li> -</ul> - -<p>Note that the <strong>obtainment mechanism</strong> for the <code>embed</code> element -- that is, the way in which a plugin is obtained if it is missing -- comes via the <code>pluginspage</code> attribute. This attribute points to a page to get the plugin if it is not detected by the browser. The <code>pluginurl</code> attribute is another attribute that can be used, and it can be used to point directly to an <a href="/cn/XPInstall" title="cn/XPInstall">XPInstall</a> file for a more streamlined download. For the <code>embed</code> element in particular, these attributes in Netscape 7 and Mozilla are governed by the Plugin Finder Service preference. Under Edit | Preferences | Navigator | Helper Applications is a preference to use Netscape's Plugin Finder Service. If the user has checked <em>Always Use the Netscape Plugin Finder Service to get Plugins</em> then whether these attributes are specified or not makes no difference -- the browser will <em>always</em> consult with the Plugin Finder Service to determine if it has a plugin to handle the missing MIME type. If the preference is unchecked, the Plugin Finder Service will be consulted only if the web page author <em>does NOT</em> specify either of these attributes.</p> - -<h3 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h3> - -<ul> - <li>作者:Arun K. Ranganathan, Netscape Communications</li> - <li>Last Updated Date: 14. Nov 2002</li> - <li>版权信息:Copyright © 2001-2003 Netscape. All rights reserved.</li> - <li>Link: <a class="external" href="http://devedge-temp.mozilla.org/viewsource/2002/markup-and-plugins/index_en.html" rel="freelink">http://devedge-temp.mozilla.org/view.../index_en.html</a></li> -</ul> - -<h4 id="References" name="References">References</h4> - -<h5 id="General_--_Specifications" name="General_--_Specifications">General -- Specifications</h5> - -<ul> - <li><a class="external" href="http://www.w3.org/TR/REC-html40">HTML 4.01 Specification</a></li> - <li><a class="external" href="http://www.w3.org/TR/xhtml1/">XHTML 1.0 Specification</a></li> -</ul> - -<h5 id="Object_Element" name="Object_Element">Object Element</h5> - -<ul> - <li><a class="external" href="http://www.w3.org/TR/REC-html40/struct/objects.html#edef-OBJECT">HTML 4.01 Specification On Object Element</a></li> -</ul> - -<h5 id="Embed_Element" name="Embed_Element">Embed Element</h5> - -<ul> - <li><a href="/cn/Gecko_Plugin_API_Reference/Plug-in_Basics" title="cn/Gecko_Plugin_API_Reference/Plug-in_Basics">Plugin API Reference on EMBED element</a> <a class="external" href="http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/intro.html#1002612">on devedge-temp</a></li> -</ul> - -<h5 id="Java" name="Java">Java</h5> - -<ul> - <li><a class="external" href="http://www.w3.org/TR/REC-html40/struct/objects.html#edef-APPLET">HTML 4.01 Applet Definition (Deprecated)</a></li> - <li><a class="external" href="http://java.sun.com/products/plugin/index.html">Java Plugin Homepage</a></li> - <li><a class="external" href="http://java.sun.com/products/plugin/versions.html">Sun Documentation on OBJECT, EMBED, and APPLET and Different Plugin Versions</a></li> - <li><a class="external" href="http://java.sun.com/products/plugin/1.4.1/demos/applets.html">Sun Demonstration of Web Pages using Applet Element</a></li> - <li><a class="external" href="http://java.sun.com/products/plugin/1.4.1/demos/plugin/applets.html">Sun Demonstration of Web Pages Using OBJECT/EMBED Elements</a></li> -</ul> - -<h5 id="Bugs_and_Future_Directions_In_Netscape_and_Mozilla" name="Bugs_and_Future_Directions_In_Netscape_and_Mozilla">Bugs and Future Directions In Netscape and Mozilla</h5> - -<ul> - <li><a href="/cn/Windows_Media_in_Netscape" title="cn/Windows_Media_in_Netscape">Windows Media in Netscape</a> Netscape 7.1 and the Windows Media ActiveX control</li> - <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=180378" title='macromedia.com - Flash ought to support &amp;lt;param name="movie..."> in addition to data attribute'>bug 180378</a></li> - <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=167601" title='FIXED: [object] Support &amp;lt;param name="PLUGINURL" ...>'>bug 167601</a></li> - <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=180411" title="Plugin Finder Service is not invoked for OBJECT element">bug 180411</a></li> -</ul> |