220 likes | 346 Views
A really fairly simple guide to: mobile browser-based application development (part 1). Chris Greenhalgh G54UBI / 2011-02-21. Content. What is a mobile browser? What’s in a web page? HTML Common file structure What is an element? From elements to view Common elements and attributes
E N D
A really fairly simple guide to:mobile browser-based application development (part 1) Chris Greenhalgh G54UBI / 2011-02-21 Chris Greenhalgh (cmg@cs.nott.ac.uk)
Content • What is a mobile browser? • What’s in a web page? • HTML • Common file structure • What is an element? • From elements to view • Common elements and attributes • Browser input files • View size on mobile devices Chris Greenhalgh (cmg@cs.nott.ac.uk)
See also • Separate slides on setting up an Android emulator, using the browser and serving static web pages Chris Greenhalgh (cmg@cs.nott.ac.uk)
What is a mobile browser? Mobile phone 1: Enter URL… 4 & 6: Runs “client-side” scripts (e.g. Javascript) 3b: Runs “Server-side” scripts (e.g. PHP) 2: Client makesHTTP requeste.g. get URL 5: Creates view & 6: Handlesuserinput Browser application Web Server network 3: Server handles HTTP request e.g. handling formsubmissionand 3c: returns response e.g. document 2: or clientreads file on phone 3a: Readsfiles on server HTML, images, … HTML, images, … Chris Greenhalgh (cmg@cs.nott.ac.uk)
What’s in a web page…? Styling (CSS) Not considered here Document Structure and content (HTML) Images and other media(JPG, PNG, …) Embedded pages and objects On-loading behaviour Behaviour (Javascript) Event-triggered behaviour Chris Greenhalgh (cmg@cs.nott.ac.uk)
HTML… Chris Greenhalgh (cmg@cs.nott.ac.uk)
A simple HTML page http://www.cs.nott.ac.uk/~cmg/G54UBI/mobile/Hello.html • <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>Hello</title> </head> <body><h1>Hello</h1> </body></html> Chris Greenhalgh (cmg@cs.nott.ac.uk)
A simple HTML page Document Type • <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> • <html> • <head> • <title>Hello</title> • </head> • <body> • <h1>Hello</h1> • </body> • </html> Document HTML Header Metadata (title) HTML page content Element (heading) Character data Chris Greenhalgh (cmg@cs.nott.ac.uk)
A simple HTML page seen as tree Document Type Document element • <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> html* Content (body) element head* body* Header (head) element title* Element (heading) h1 Metadata (title) element Hello Hello Character data Character data * Required elements Chris Greenhalgh (cmg@cs.nott.ac.uk)
A slightly more complicated page http://www.cs.nott.ac.uk/~cmg/G54UBI/mobile/Element.html • <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>Hello</title> </head> <body> <h1>Hello</h1> • <p style="font-size: 10"> Some 10-point text, <b>Bold</b> </p> </body></html> Chris Greenhalgh (cmg@cs.nott.ac.uk)
An example element Element name Attribute name Element value • <p style="font-size: 10"> • Some 10-point text, • <b> Bold </b> • </p> Begin tag Child Character data Child element End tag Note: end tags are only used for some elements in HTML (but for all elements in XHTML and XML) Chris Greenhalgh (cmg@cs.nott.ac.uk)
Example element as tree Attributes: “Paragraph” p style “font-size: 10” “Bold” “Some 10-point text,” b “Bold” Has attribute Has child Chris Greenhalgh (cmg@cs.nott.ac.uk)
HTML generic structure • Text document describing a “tree” of data • Comprising “elements” with “attributes” and “children”, including other elements and “character data” • like XML, based on SGML • Several versions including HTML4, XHTML, and HTML5 Chris Greenhalgh (cmg@cs.nott.ac.uk)
HTML, structure, content and style • The tags describe: • the logical structure of the document • E.g. “heading”, “paragraph”, “link” • Some elements of style, but this is NOT recommended in general • E.g. “<b>bold text</b>” • The attributes describe: • More about each element, e.g. font style, link URL • The character data is the visible content Chris Greenhalgh (cmg@cs.nott.ac.uk)
From elements to views… p style “font-size: 10” “Some 10-point text,” b “Bold” Chris Greenhalgh (cmg@cs.nott.ac.uk)
HTML specifications • Each version of HTML specifies • What the elements are • What attributes each element can (or must) have • Which elements can have children, and if so which child elements they can have • Each browser may also support slightly different elements and/or attributes, or support them in slightly different ways • Details are out of scope for this course Chris Greenhalgh (cmg@cs.nott.ac.uk)
Some common HTML elements • <h1>…</h1>, <h2>…</h2>, … - Headings • <p>…</p> - Paragraph • <div>…</div> - an arbitrary section (“division”) • <br> - line-break • <hr> - horizontal rule (line) • <ul><li>…</li>…</ul> - Un-numbered list and one list item • <a href=“URL”>LABEL</a> - hyperlink (“Anchor”) • <imgsrc=“URL” alt=“TEXT”/> - image • <input type=“button” value=“Go!”/> - a button Chris Greenhalgh (cmg@cs.nott.ac.uk)
Special HTML Attributes • Every content element can have the following special attributes: • id – specifies a unique identity (name) for the element, that can be referred to elsewhere • No two elements can have the same ID • class – specifies a “class” name for the element, generally used to identify a particular visual appearance to be specified elsewhere • Any number of elements can have the same class Chris Greenhalgh (cmg@cs.nott.ac.uk)
Browser input files Image file(s).png, .jpg, … HTML file .html, .htm Inline… External… <imgsrc=“…”> Script file(s).js <script>…</script> <script src=“…“></script> <… style=“…”> <link rel="stylesheet" href=“…”> <H1>Hello…</H1> <frame src=“…”> Style file(s).css So there could just be an HTML file, or there could be several other linked files as well Chris Greenhalgh (cmg@cs.nott.ac.uk)
View size on mobile devices • By default most mobile browsers pretend to have screen width of about 900 pixels • Which is why the example pages look small when viewed on the emulator • A meta tag in the HTML page header can tell the mobile browser to use its “real” width, which is 320 (CSS) pixels on most mobiles: • <meta name="viewport" content="width=device-width"> • See http://www.cs.nott.ac.uk/~cmg/G54UBI/mobile/HelloMobile.html Chris Greenhalgh (cmg@cs.nott.ac.uk)
Conclusions • HTML is used to specify the (tree) structure and content of a web page • There is a standard document structure • There are standard elements and attributes • You should now be able to • Read and roughly understand an HTML file • Create and edit simple static HTML files Chris Greenhalgh (cmg@cs.nott.ac.uk)
Other resources • The WWW Consortium, http://www.w3.org/ • HTML 4.01 specification, http://www.w3.org/TR/html401/ • Online tutorials, e.g. • http://www.w3schools.com/ Chris Greenhalgh (cmg@cs.nott.ac.uk)