HTML5 for Web Designers



字数:0 关键词: HTML5 前端技术 HTML

?KDC,=FI N<9;E tag. The img element later appeared in the HTML 2.0 specification. The role of the IETF was superceded by the W3C, the World Wide Web Consortium, where subsequent iterations of the HTML standard have been published at The latter half of the nineties saw a flurry of revisions to the specification until HTML 4.01 was published in 1999. At that time, HTML faced its first major turning point. O?KDC(1?KDC8JODC After HTML 4.01, the next revision to the language was called XHTML 1.0. The X stood for “eXtreme” and web developers were required to cross their arms in an X shape when speak- ing the letter. No, not really. The X stood for “eXtensible” and arm crossing was entirely optional. The content of the XHTML 1.0 specification was identical to that of HTML 4.01. No new elements or attributes were added. The only difference was in the syntax of the language. Whereas HTML allowed authors plenty of freedom in how 3 they wrote their elements and attributes, XHTML required authors to follow the rules of XML, a stricter markup language upon which the W3C was basing most of their technologies. Having stricter rules wasn’t such a bad thing. It encouraged authors to use a single writing style. Whereas previously tags and attributes could be written in uppercase, lowercase, or any combination thereof, a valid XHTML 1.0 document re- quired all tags and attributes to be lowercase. The publication of XHTML 1.0 coincided with the rise of browser support for CSS. As web designers embraced the emergence of web standards, led by The Web Standards Project, the stricter syntax of XHTML was viewed as a “best practice” way of writing markup. Then the W3C published XHTML 1.1. While XHTML 1.0 was simply HTML reformulated as XML, XHTML 1.1 was real, honest-to-goodness XML. That meant it couldn’t be served with a mime-type of text/html. But if authors published a document with an XML mime-type, then the most popular web browser in the world at the time— Internet Explorer—couldn’t render the document. It seemed as if the W3C were losing touch with the day-to-day reality of publishing on the web. O?KDC)1F?#N<ËI<EFK>FEE8K8B<@K If Dustin Hoffman’s character in The Graduate had been a web designer, the W3C would have said one word to him, just one word: XML. As far as the W3C was concerned, HTML was finished as of version 4. They began working on XHTML 2, designed to lead the web to a bright new XML-based future. A BRIEF HISTORY OF MARKUP 4 HTML5 FOR WEB DESIGNERS Although the name XHTML 2 sounded very similar to XHTML 1, they couldn’t have been more different. Unlike XHTML 1, XHTML 2 wasn’t going to be backwards compat- ible with existing web content or even previous versions of HTML. Instead, it was going to be a pure language, unbur- dened by the sloppy history of previous specifications. It was a disaster. K?<J:?@JD1N?8KN>K=6 A rebellion formed within the W3C. The consortium seemed to be formulating theoretically pure standards unrelated to the needs of web designers. Representatives from Opera, Apple, and Mozilla were unhappy with this direction. They wanted to see more emphasis placed on formats that allowed the cre- ation of web applications. Things came to a head in a workshop meeting in 2004. Ian Hickson, who was working for Opera Software at the time, proposed the idea of extending HTML to allow the creation of web applications. The proposal was rejected. The disaffected rebels formed their own group: the Web Hypertext Application Technology Working Group, or WHATWG for short. =IFDN<98GGJ(%'KF?KDC, From the start, the WHATWG operated quite differently than the W3C. The W3C uses a consensus-based approach: issues are raised, discussed, and voted on. At the WHATWG, issues are also raised and discussed, but the final decision on what goes into a specification rests with the editor. The editor is Ian Hickson. 5 On the face of it, the W3C process sounds more democratic and fair. In practice, politics and internal bickering can bog down progress. At the WHATWG, where anyone is free to contribute but the editor has the last word, things move at a faster pace. But the editor doesn’t quite have absolute power: an invitation-only steering committee can impeach him in the unlikely event of a Strangelove scenario. Initially, the bulk of the work at the WHATWG was split into two specifications: Web Forms 2.0 and Web Apps 1.0. Both specifications were intended to extend HTML. Over time, they were merged into a single specification called simply HTML5. IC@M<O?KDCJPEK8O The fog of confusion began to clear in 2009. The W3C an- nounced that the charter for XHTML 2 would not be re- newed. The format had been as good as dead for several years; this announcement was little more than a death certificate. Strangely, rather than passing unnoticed, the death of XHTML 2 was greeted with some mean-spirited gloating. XML naysayers used the announcement as an opportunity to deride anyone who had ever used XHTML 1—despite the fact that XHTML 1 and XHTML 2 have almost nothing in common. Meanwhile, authors who had been writing XHTML 1 in order to enforce a stricter writing style became worried that HTML5 would herald a return to sloppy markup. As you’ll soon see, that’s not necessarily the case. HTML5 is as sloppy or as strict as you want to make it. K?<K@DE F=?KDC, the french revolution was an era of extreme political and social change. Revolutionary fervor was applied to time itself. For a brief period, the French Republic introduced a decimal time system, with each day divided into ten hours and each hour divided into one hundred minutes. It was thor- oughly logical and clearly superior to the sexagesimal system. Decimal time was a failure. Nobody used it. The same could be said for XHTML 2. The W3C rediscovered the lesson of post-revolutionary France: changing existing behavior is very, very difficult. ;EGI@E:@GC@KI<8C The creation of HTML5 has been driven by an ongoing inter- nal tension. On the one hand, the specification needs to be powerful enough to support the creation of web applications. On the other hand, HTML5 needs to support existing con- tent, even if most existing content is a complete mess. If the 11 specification strays too far in one direction, it will suffer the same fate as XHTML 2. But if it goes too far in the other direc- tion, the specification will enshrine tags and tables for layout because, after all, that’s what a huge number of web pages are built with. It’s a delicate balancing act that requires a pragmatic, level- headed approach. The HTML5 specification doesn’t just declare what browsers should do when they are processing well-formed markup. For the first time, a specification also defines what browers should do when they are dealing with badly formed documents. Until now, browser makers have had to individually figure out how to deal with errors. This usually involved reverse engineering whatever the most popular browser was doing— not a very productive use of their time. It would be better for browser makers to implement new features rather than waste their time duplicating the way their competitors handle mal- formed markup. Defining error handling in HTML5 is incredibly ambitious. Even if HTML5 had exactly the same elements and attributes as HTML 4.01, with no new features added, defining error handling by 2012 would still be a Sisyphean task. Error handling might not be of much interest to web design- ers, especially if we are writing valid, well-formed documents to begin with, but it’s very important for browser makers. Whereas previous markup specifications were written for authors, HTML5 is written for authors and implementers. Bear that in mind when perusing the specification. It explains why the HTML5 specification is so big and why it seems to have been written with a level of detail normally reserved for THE DESIGN OF HTML5 12 HTML5 FOR WEB DESIGNERS trainspotters who enjoy a nice game of chess while indexing their stamp collection. >@M<@KKFD<JKI8@>?K#;F:KPG< A Document Type Declaration, or doctype for short, has traditionally been used to specify which particular flavor of markup a document is written in. The doctype for HTML 4.01 looks like this (line wraps marked »): Here’s the doctype for XHTML 1.0: They’re not very human-readable, but, in their own way, they are simply saying “this document is written in HTML 4.01,” or “this document is written in XHTML 1.0.” You might expect the doctype declaring “this document is written in HTML5” would have the number five in it some- where. It doesn’t. The doctype for HTML5 looks like this: It’s so short that even I can memorize it. But surely this is madness! Without a version number in the doctype, how will we specify future versions of HTML? 13 When I first saw the doctype for HTML5, I thought it was the height of arrogance. I asked myself, “Do they really believe that this will be the final markup specification ever written?” It seemed to be a textbook case of Year Zero thinking. In fact, though, the doctype for HTML5 is very pragmatic. Because HTML5 needs to support existing content, the doc- type could be applied to an existing HTML 4.01 or XHTML 1.0 document. Any future versions of HTML will also need to support the existing content in HTML5, so the very concept of applying version numbers to markup documents is flawed. The truth is that doctypes aren’t even important. Let’s say you serve up a document with a doctype for HTML 4.01. If that document includes an element from another specifica- tion, such as HTML 3.2 or HTML5, a browser will still render that part of the document. Browsers support features, not doctypes. Document Type Declarations were intended for validators, not browsers. The only time that a browser pays any attention to a doctype is when it is performing “doctype switching”— a clever little hack that switches rendering between quirks mode and standards mode depending on the presence of a decent doctype. The minimum information required to ensure that a browser renders using standards mode is the HTML5 doctype. In fact, that’s the only reason to include the doctype at all. An HTML document written without the HTML5 doctype can still be valid HTML5. B<@KJ@DGC< The doctype isn’t the only thing that has been simplified in HTML5. THE DESIGN OF HTML5 14 HTML5 FOR WEB DESIGNERS If you want to specify the character encoding of a markup document, the best way is to ensure that your server sends the correct Content-Type header. If you want to be doubly certain, you can also specify the character set using a tag. Here’s the meta declaration for a document written in HTML 4.01: Here’s the much more memorable way of doing the same thing in HTML5: As with the doctype, this simplified character encoding contains the minimum number of characters needed to be interpreted by browsers. The Browsers don’t need that attribute. They will assume that the script is written in JavaScript, the most popular scripting lan- guage on the web (let’s be honest: the only scripting language on the web): Likewise, you don’t need to specify a type value of “text/css” every time you link to a CSS file: 15 You can simply write: JPEK8O1D8IB@E>@KLGPFLIN8P Some programming languages, such as Python, enforce a particular way of writing instructions. Using spaces to indent code is mandatory—the white space is significant. Other pro- gramming languages, such as JavaScript, don’t pay any atten- tion to formatting—the white space at the start of a line isn’t significant. If you’re looking for a cheap evening’s entertainment, get an array of programmers into the same room and utter the words “significant white space.” You can then spend hours warming yourself by the ensuing flame war. There’s a fundamental philosophical question at the heart of the significant white space debate: should a language enforce a particular style of writing, or should authors be free to write in whatever style they like? Markup doesn’t require significant white space. If you want to add a new line and an indentation every time you nest an element, you can do so, but browsers and validators don’t re- quire it. This doesn’t mean that markup is a free-for-all. Some flavors of markup enforce a stricter writing style than others. Before XHTML 1.0, it didn’t matter if you wrote tags in upper- case or lowercase. It didn’t matter whether or not you quoted attributes. For some elements, it didn’t even matter whether you included the closing tag. XHTML 1.0 enforces the syntax of XML. All tags must be writ- ten in lowercase. All attributes must be quoted. All elements THE DESIGN OF HTML5 16 HTML5 FOR WEB DESIGNERS must have a closing tag. In the special case of standalone ele- ments such as br, the requirement for a closing tag is replaced with a requirement for a closing slash:
. With HTML5, anything goes. Uppercase, lowercase, quoted, unquoted, self-closing or not; it’s entirely up to you. I’ve been using the XHTML 1.0 doctype for years. I like the fact that I must write in one particular style and I like the way that the W3C validator enforces that style. Now that I’m using HTML5, it’s up to me to enforce the style I want. I can see why some people don’t like the looseness of the HTML5 syntax. It seems like it’s turning the clock back on years of best practices. Some people have even said that the lax syntax of HTML5 is encouraging bad markup. I don’t think that’s true, but I can see why it’s a concern. It’s as if a programming language that enforced significant white space suddenly changed over to a more forgiving rule set. Personally, I’m okay with the casual syntax of HTML5. I’ve come to terms with having to enforce my own preferred writ- ing style myself. But I would like to see more tools that would allow me to test my markup against a particular style. In the world of programming, these are called lint tools: programs that flag up suspect coding practices. A lint tool for markup would be different than a validator, which checks against a doctype; but it would be wonderful if the two could be com- bined into one lean, mean validating linting machine. Whosoever shall program such a device will earn the undying respect and admiration of web designers everywhere. N<;FEËKLJ<K?8KB@E;F=C8E>L8>< In past versions of HTML, whenever a previously existing element or attribute was removed from the specification, the process was called deprecation. Web designers were advised 17 not to use deprecated elements, or send them Christmas cards, or even mention them in polite company. There are no deprecated elements or attributes in HTML5. But there are plenty of obsolete elements and attributes. No, this isn’t a case of political correctness gone mad. “Obso- lete” has a subtly different meaning from “deprecated.” Because HTML5 aims to be backwards compatible with exist- ing content, the specification must acknowledge previously existing elements even when those elements are no longer in HTML5. This leads to a slightly confusing situation where the specification simultaneously says, “authors, don’t use this element” and, “browsers, here’s how you should render this element.” If the element were deprecated, it wouldn’t be men- tioned in the specification at all; but because the element is obsolete, it is included for the benefit of browsers. Unless you’re building a browser, you can treat obsolete ele- ments and attributes the same way you would treat deprecated elements and attributes: don’t use them in your web pages and don’t invite them to cocktail parties. If you insist on using an obsolete element or attribute, your document will be “non-conforming.” Browsers will render everything just fine, but you might hear a tut-ing sound from the website next door. So long, been good to know ya The frame, frameset, and noframes elements are obsolete. They won’t be missed. The acronym element is obsolete, thereby freeing up years of debating time that can be better spent calculating the angel-density capacity of standard-sized pinheads. Do not mourn the acronym element; just use the abbr element in- stead. Yes, I know there’s a difference between acronyms and THE DESIGN OF HTML5 18 HTML5 FOR WEB DESIGNERS abbreviations—acronyms are spoken as single words, like NATO and SCUBA—but just remember: all acronyms are ab- breviations, but not all abbreviations are acronyms. Presentational elements such as font, big, center, and strike are obsolete in HTML5. In reality, they’ve been obsolete for years; it’s much easier to achieve the same presentational effects using CSS properties such as font-size and text- align. Similarly, presentational attributes such as bgcolor, cellspacing, cellpadding, and valign are obsolete. Just use CSS instead. Not all presentational elements are obsolete. Some of them have been through a re-education program and given one more chance. KLIE=8:<K?<JKI8E><:?$:?$:?8E> tags; titles of works are usually italicized; people’s names aren’t usually italicized; therefore the cite element shouldn’t be used for marking up people’s names. That’s just plain wrong. I’m in favor of HTML5 taking its lead from browsers, but this is a case of the tail wagging the dog. Fortunately, no validator can possibly tell whether the text between opening and closing tags refers to a person or not, so there’s nothing to stop us web designers from using the cite element in a sensible, backwards compatible way. The a element on steroids While the changes to previously existing elements involve creative wordplay, there’s one element that’s getting a super- charged makeover in HTML5. THE DESIGN OF HTML5 20 HTML5 FOR WEB DESIGNERS The a element is, without a doubt, the most important element in HTML. It turns our text into hypertext. It is the connective tissue of the World Wide Web. The a element has always been an inline element. If you want- ed to make a headline and a paragraph into a hyperlink, you would have to use multiple a elements:

About me

Find out what makes me tick.

In HTML5, you can wrap multiple elements in a single a element:

About me

Find out what makes me tick.

The only caveat is that you can’t nest an a element within an- other a element. Wrapping multiple elements in a single a element might seem like a drastic change, but most browsers won’t have to do much to support this new linking model. They already sup- port it even though this kind of markup has never been tech- nically legal until now. This seems slightly counter-intuitive: Surely the browsers should be implementing an existing specification? Instead, the newest specification is documenting what browsers are already doing. J?@EPE If you put anything between the opening and closing tags, only browsers that don’t support canvas will see it (fig 3.01): RICH MEDIA 24 HTML5 FOR WEB DESIGNERS

No canvas support? Have an old-fashioned image » instead:

a cute puppy
All the hard work is done in JavaScript. First of all, you’ll need to reference the canvas element and its context. The word “context” here simply means an API. For now, the only con- text is two-dimensional: var canvas = document.getElementById('my-first-canvas'); var context = canvas.getContext('2d'); Now you can start drawing on the two-dimensional surface of the canvas element using the API documented in the HTML5 specification at The 2D API offers a lot of the same tools that you find in a graphics program like Illustrator: strokes, fills, gradients, shad- ows, shapes, and Bézier curves. The difference is that, instead fig 3.01: Users without canvas support will see the image of a cute puppy. 1. The long URL: multipage/the-canvas-element.html 25 of using a Graphical User Interface, you have to specify every- thing using JavaScript. Dancing about architecture: drawing with code This is how you specify that the stroke color should be red: context.strokeStyle = '#990000'; Now anything you draw will have a red outline. For example, if you want to draw a rectangle, use this syntax: strokeRect ( left, top, width, height ) If you want to draw a rectangle that’s 100 by 50 pixels in size, positioned 20 pixels from the left and 30 pixels from the top of the canvas element, you’d write this (fig 3.02): context.strokeRect(20,30,100,50); That’s one very simple example. The 2D API provides lots of methods: fillStyle, fillRect, lineWidth, shadowColor and many more. In theory, any image that can be created in a program like Illustrator can be created in the canvas element. In practice, doing so would be laborious and could result in excessively long JavaScript. Besides, that isn’t really the point of canvas. RICH MEDIA fig 3.02: A rectangle, drawn with canvas. 26 HTML5 FOR WEB DESIGNERS Canvas. Huh! What is it good for? It’s all well and good using JavaScript and canvas to create im- ages on the fly, but unless you’re a hardcore masochist, what’s the point? The real power of canvas is that its contents can be updated at any moment, drawing new content based on the actions of the user. This ability to respond to user-triggered events makes it possible to create tools and games that would have previously required a plug-in technology such as Flash. One of the first flagship demonstrations of the power of canvas came from Mozilla Labs. The Bespin application ( is a code editor that runs in the browser (fig 3.03). It is very powerful. It is very impressive. It is also a perfect example of what not to do with canvas. fig 3.03: The Bespin application, built with canvas. 27 Access denied A code editor, by its nature, handles text. The Bespin code editor handles text within the canvas element—except that it isn’t really text anymore; it’s a series of shapes that look like text. Every document on the web can be described with a Docu- ment Object Model. This DOM can have many different nodes, the most important of which are element nodes, text nodes, and attributes. Those three building blocks are enough to put together just about any document you can imagine. The canvas element has no DOM. The content drawn within canvas cannot be represented as a tree of nodes. Screen readers and other assistive technology rely on having access to a Document Object Model to make sense of a docu- ment. No DOM, no access. The lack of accessibility in canvas is a big problem for HTML5. Fortunately there are some very smart people work- ing together as a task force to come up with solutions (http:// Canvas accessibility is an important issue and I don’t want any proposed solutions to be rushed. At the same time, I don’t want canvas to hold up the rest of the HTML5 spec. Clever canvas Until the lack of accessibility is addressed, it might seem as though canvas is off-limits to web designers. But it ain’t neces- sarily so. Whenever I use JavaScript on a website, I use it as an en- hancement. Visitors who don’t have JavaScript still have ac- cess to all the content, but the experience might not be quite RICH MEDIA 2. The long URL: 28 HTML5 FOR WEB DESIGNERS as dynamic as in a JavaScript-capable environment. This multi-tiered approach, called Unobtrusive JavaScript, can also be applied to canvas. Instead of using canvas to create content, use it to recycle existing content. Suppose you have a table filled with data. You might want to illustrate the trends in the data using a graph. If the data is static, you can generate an image of a graph—using the Google Chart API, for example. If the data is editable, updating in re- sponse to user-triggered events, then canvas is a good tool for generating the changing graph. Crucially, the content repre- sented within the canvas element is already accessible in the pre-existing table element. The clever folks at Filament Group have put together a jQuery plug-in for that very situation (fig 3.04; html5/3).3 There is another option. Canvas isn’t the only API for gener- ating dynamic images. SVG, Scalable Vector Graphics, is an 3. The long URL: accessible_charts_graphs_from_tables_html5_canvas/ fig 3.04: Using canvas to generate a graph from data input by users. 29 XML format that can describe the same kind of shapes as can- vas. Because XML is a text-based data format, the contents of SVG are theoretically available to screen readers. In practice, SVG hasn’t captured the imagination of develop- ers in the same way that canvas has. Even though canvas is the new kid on the block, it already enjoys excellent browser support. Safari, Firefox, Opera, and Chrome support canvas. There’s even a JavaScript library that adds canvas support to Internet Explorer ( Given its mantras of “pave the cowpaths,” and “don’t reinvent the wheel,” it might seem odd that the WHATWG would advocate canvas in HTML5 when SVG already exists. As is so often the case, the HTML5 specification is really just documenting what browsers already do. The canvas element wasn’t dreamt up for HTML5; it was created by Apple and implemented in Safari. Other browser makers saw what Apple was doing, liked what they saw, and copied it. It sounds somewhat haphazard, but this is often where our web standards come from. Microsoft, for example, created the XMLHttpRequest object for Internet Explorer 5 at the end of the 20th century. A decade later, every browser supports this feature and it’s now a working draft in last call at the W3C. In the Darwinian world of web browsers, canvas is spread- ing far and wide. If it can adapt for accessibility, its survival is ensured. 8L;@F The first website I ever made was a showcase for my band. I wanted visitors to the site to be able to listen to the band’s songs. That prompted my journey into the underworld to investigate the many formats and media players competing RICH MEDIA 4. The long URL: 30 HTML5 FOR WEB DESIGNERS for my attention: QuickTime, Windows Media Player, Real Audio—I spent far too much time worrying about relative market share and cross-platform compatibility. In the intervening years, the MP3 format has won the battle for ubiquity. But providing visitors with an easy way to listen to a sound file still requires a proprietary technology. The Flash player has won that battle. Now HTML5 is stepping into the ring in an attempt to take on the reigning champion. Embedding an audio file in an HTML5 document is simple: That’s a little too simple. You probably want to be a bit more specific about what the audio should do. Suppose there’s an evil bastard out there who hates the web and all who sail her. This person probably doesn’t care that it’s incredibly rude and stupid to embed an audio file that plays automatically. Thanks to the autoplay attribute, such malevo- lent ambitions can be realized: If you ever use the autoplay attribute in this way, I will hunt you down. Notice that the autoplay attribute doesn’t have a value. This is known as a Boolean attribute, named for that grand Cork mathematician George Boole. Computer logic is based entirely on Boolean logic: an electric current is either flowing or it isn’t; a binary value is either one or zero; the result of a computation is either true or false. 31 Don’t confuse Boolean attributes with Boolean values. You’d be forgiven for thinking that a Boolean attribute would take the values “true” or “false.” Actually, it’s the very existence of the attribute that is Boolean in nature: either the attribute is in- cluded or it isn’t. Even if you give the attribute a value, it will have no effect. Writing autoplay="false" or autoplay="no thanks" is the same as writing autoplay. If you are using XHTML syntax, you can write autoplay= "autoplay". This is brought to you by the Department of Redundancy Department. When an auto-playing audio file isn’t evil enough, you can in- flict even more misery by having the audio loop forever. An- other Boolean attribute, called loop, fulfills this dastardly plan: Using the loop attribute in combination with the autoplay attribute in this way will renew my determination to hunt you down. Out of control The audio element can be used for good as well as evil. Giving users control over the playback of an audio file is a sensible idea that is easily accomplished using the Boolean attribute controls: The presence of the controls attribute prompts the browser to provide native controls for playing and pausing the audio, as well as adjusting the volume (fig 3.05). If you’re not happy with the browser’s native controls, you can create your own. Using JavaScript, you can interact with RICH MEDIA 32 HTML5 FOR WEB DESIGNERS the Audio API, which gives you access to methods such as play and pause and properties such as volume. Here’s a quick ’n’ dirty example using button elements and nasty inline event handlers (fig 3.06):
Buffering At one point, the HTML5 spec included another Boolean attribute for the audio element. The autobuffer attribute was more polite and thoughtful than the nasty autoplay attribute. It provided a way for authors to inform the browser fig 3.05: Use controls to display play, pause, and volume controls for your audio. 33 that—although the audio file shouldn’t play automatically—it will probably be played at some point, so the browser should start pre-loading the file in the background. This would have been a useful attribute, but unfortunately Safari went a step further. It preloaded audio files regardless of whether or not the autobuffer attribute was present. Re- member that because autobuffer was a Boolean attribute, there was no way to tell Safari not to preload the audio: autobuffer="false" was the same as autobuffer="true" or any other value The autobuffer attribute has now been replaced with the preload attribute. This isn’t a Boolean attribute. It can take three possible values: none, auto, and metadata. Using preload="none", you can now explicitly tell browsers not to pre-load the audio: If you only have one audio element on a page, you might want to use preload="auto", but the more audio elements you have, the more your visitors’ bandwidth is going to get ham- mered by excessive preloading. You play to-may-to, I play to-mah-to The audio element appears to be nigh-on perfect. Surely there must be a catch somewhere? There is. The problem with the audio element isn’t in the specification. The problem lies with audio formats. RICH MEDIA fig 3.06: The controls produced by the button elements. 5. The long URL: 34 HTML5 FOR WEB DESIGNERS Although the MP3 format has become ubiquitous, it is not an open format. Because the format is patent-encumbered, technologies can’t decode MP3 files without paying the patent piper. That’s fine for corporations like Apple or Adobe, but it’s not so easy for smaller companies or open-source groups. Hence, Safari will happily play back MP3 files while Firefox will not. There are other audio formats out there. The Vorbis codec— usually delivered as an .ogg file—isn’t crippled by any patents. Firefox supports Ogg Vorbis—but Safari doesn’t. Fortunately, there’s a way to use the audio element without having to make a Sophie’s Choice between file formats. In- stead of using the src attribute in the opening



需要 6 金币 [ 分享文档获得金币 ] 0 人已下载