Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
Introducing Plug-Ins
Plug-ins were introduced by Netscape in Navigator 3.0. Rather than adding support directly to the browser for media types such as formatted text, video, and audio, Netscape created a modular architecture that allows programmers to write their own browser add-ons for these features.
There are now hundreds of plug-ins available for both Netscape and Internet Explorer. Here are a few of the most popular:
- Macromedia's ShockWave and Flash plug-ins support animation and video.
- Adobe's Acrobat plug-in supports precisely formatted, cross-platform text.
- RealPlayer supports streaming audio and video.
- Headspace's Beatnik plug-in supports music in Web pages.
Netscape and Internet Explorer use different plug-in formats and usually require different versions of a plug-in. Additionally, some plug-ins are available only for one platform, such as Windows or Macintosh.
Because Netscape's LiveAudio plug-in and Microsoft's Windows Media Player are included with Netscape 4.x and Internet Explorer, you can assume that much of your Web page's audience will have a plug-in for playing sounds. The workshop section of this hour will use these plug-ins to play sounds.
Using the <embed> Tag
You can include a file that uses a plug-in in a Web document with the <embed> tag. This tag specifies the filename for the content and any parameters required by the plug-in. Here is a simple example:
<embed SRC="sound.wav" HIDDEN=true AUTOSTART=false LOOP=false>
This example embeds the file sound.wav. The <embed> tag for sounds uses the following attributes:
- The SRC attribute specifies the filename of the sound file.
- The HIDDEN attribute makes the embedded object invisible on the page; without this attribute, a control panel is displayed to play or stop the sound.
- The AUTOSTART attribute controls whether the sound should play immediately when the page loads.
- The LOOP attribute specifies whether the sound will repeat—this is more useful for MIDI music files than simple sounds.
- The CONTROLS attribute specifies the type of control panel that is used if HIDDEN is not specified. Values include "console" for a large panel, "smallconsole" for a smaller panel, or "playbutton" for a simple Play button.
- The WIDTH and HEIGHT attributes control the size of the control panel, if it is not hidden.
Using the <object> Tag
The <embed> tag has been deprecated in the HTML 4.0 standard in favor of a new tag, <object>. This tag allows you to specify the same parameters and many others to embed a sound or other plug-in object. Here is an example <object> tag to include a sound within a Web page:
<object type="audio/x-wav" data="sound.wav" width="100" height="50"> <param name="src" value="sound.wav"> <param name="autostart" value="false"> <param name="hidden" value="true"> </object>
This tag embeds a hidden sound object, similar to the <embed> tag example in the previous section.
Understanding MIME Types
Multipurpose Internet Mail Extensions (MIME) is a standard for classifying different types of files and transmitting them over the Internet. The different types of files are known as MIME types.
You've already worked with a few MIME types: HTML (MIME type text/html), text (MIME type text/plain), and GIF images (MIME type image/gif). Although Web browsers don't normally support many more than these types, external applications and plug-ins can provide support for additional types.
When a Web server sends a document to a browser, it includes that document's MIME type in the heading. If the browser supports that MIME type, it displays the file. If not, you're asked what to do with the file (such as when you click on a .zip or .exe file to download it).
Working with Plug-In Objects | Next Section

Account Sign In
View your cart