190 likes | 301 Vues
This guide explores the Document Object Model (DOM) and its tree-like structure, detailing how to navigate nodes and their relationships. It also covers the implementation of multimedia elements such as audio and video in HTML5, along with how to effectively use widgets in web pages. Key considerations for integrating widgets, including potential issues with divs, formatting, and validation, are discussed. Developers will learn the best practices for adding multimedia features to enhance user experience while ensuring compatibility and functionality.
E N D
DOM, Multimedia and Widgets 20February 2014
Navigating a Tree • NodeA.firstChild = NodeA1 • NodeA.lastChild = NodeA3 • NodeA1.parentNode = NodeA • NodeA1.nextSibling = NodeA2 • NodeA3.prevSibling = NodeA2 • NodeA.lastChild.firstChild = NodeA3a
Relating To HTML • Look at Inspect Element Root = HTML Children and siblings • Structure is called the DOM Document Object Model • CSS will allow us to format selectively based on the tree
CSS Selectors • context tag { • Applies to any tag inside context • Space is a descendant selector • context > tag { • Applies to any tag directly inside context • > is a child selector • Context + tag { • Applies only to a tag that DIRECTLY follows a context • + is an adjacent sibling selector
Sound Options • You can add it to the page – not recommended • Widgets (coming next) • Natively in HTML5 <audio controls> <source src="h.wav" type="audio/wav"> </audio> Warning: may not work until uploaded
Videos • Options • Widgets (coming next) • Iframes (Youtube) • Natively in HTML5 <video controls> <source src="m.mp4" type="video/mp4" /> </video> Warning: may not work until uploaded
Other Documents • Object <object data="cauliflower.pdf"></object> • pdf: can open in a browser, but not part of your website
Review: Viewing a Web Page SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions 2 1 3 Server Client Web Server Pages Browser
Dynamic Web Pages • Two places you can change • Browser: JavaScript • Server: php • General rule: • do it in the browser if you can • Why? • Distribute the work • Consider the difference in the time function… 2 1 3 Server Client Web Server Pages Browser
What is JavaScript? • Functions • simple programming tool • dynamic text • react to events • read and write HTML elements • w3schools
HTML Content CSS Presentation JavaScript Behavior Three Legged Stool
Widgets • A chunk of code that you can embed in an existing environment • Differences • Resides: desktop or web • Embedding: any page or application or limited • Runs: your machine or server
Widget Websites • Lots of sites • See resources • Or just Google • Let’s add some to a web page • Adding • Formatting: • Enclose in div • position and format • Warning: make sure that your browser isn’t blocking them
Problems with Widgets • They have divs in them that you can’t see • Implicaton: if you format all divs, it applies to the ones in the widget • Solution: name all divs with class or use section or main, header, … • They may use & or blank in URLs • Implication: won’t validate • Solution: replace all &s with & and all blanks with %20 • They may be old • Don’t use if too many obsolete tags
Steps for adding a widget • Assure that you have no unnamed divs • Layout your page with a placeholder div that is the size of the widget that you are going to add • Add the widget inside the div • Assure that it looks the way that you want • Format the embedded code without any changes • Replace all inline formatting with classes and css • Assure that it still looks right • Eliminate any unneeded tags or css entries • Assure that it still looks right • Replace all & and blanks as needed • Validate