cse 190: internet e-commerce

14
CSE 190: Internet E- Commerce Lecture 3

Upload: mortimer-coulon

Post on 31-Dec-2015

25 views

Category:

Documents


4 download

DESCRIPTION

CSE 190: Internet E-Commerce. Lecture 3. Programming Internet Explorer. Today’s talk covers: Navigating the Document Object Model (DOM) Responding to IE’s Event system Challenges and limitations Browser Helper Objects. Resources. Document Object Model, Programming the IE, DHTML Links: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE 190: Internet E-Commerce

CSE 190: Internet E-Commerce

Lecture 3

Page 2: CSE 190: Internet E-Commerce

Programming Internet Explorer

Today’s talk covers:

• Navigating the Document Object Model (DOM)

• Responding to IE’s Event system

• Challenges and limitations

• Browser Helper Objects

Page 3: CSE 190: Internet E-Commerce

Resources

• Document Object Model, Programming the IE, DHTML

• Links:

– http://wsabstract.com/javatutors/dom2.shtml– http://wsabstract.com/javatutors/dom4.shtml– http://wsabstract.com/javatutors/dom5.shtml– http://wsabstract.com/javatutors/dom6.shtml

• Reference Book: Programming Microsoft Internet Explorer 5 by Scott Roberts

Page 4: CSE 190: Internet E-Commerce

Document Object Model (DOM)

• HTML/DOM Example 1.htm, DOM Example 2.htm

Page 5: CSE 190: Internet E-Commerce

Internet Explorer:

DOM Top Level:

Document Object Model (DOM)(Scott Robert’s book: chapter 11: html spy)

Accessing the DOM:• Hosting the Control• Loading the page• Walking the tree

Page 6: CSE 190: Internet E-Commerce

Why use IE?Alternatives:• Mozilla, KDE, WinInet, socket libraries

Benefits:• Dominant platform• Javascript compatibility• Programmatic ease

Drawbacks:• Scalability• Black box

Page 7: CSE 190: Internet E-Commerce

Walking tree Program example Chapter 6: VBWebhost example

Dim doc as HTMLDocumentDim elem as IHTMLElement

Set doc = WebBrowser1.Document

‘ Show HTML of document, from <body>..</body>MsgBox doc.body.innerHTML

For each elem in doc.allMsgBox elem.tag & “ “ & elem.innerHTML

Next

‘ Find named elementMsgBox doc.all( “foo” ).tag

‘Find first form, change contents of username field (no onChange event)doc.forms(0).Item( “username” ).Value = “cypherpunk”

Page 8: CSE 190: Internet E-Commerce

Walking tree, interfaces

IWebBrowser2

IHTMLWindow

IHTMLDocument

IHTMLBodyElement

IHTMLFormElement

IHTMLAnchorElement

IHTMLImgElement

IHTMLInputTextElement

IHTMLFrameElement

Page 9: CSE 190: Internet E-Commerce

Loading page

‘ GET urlBrowser.Navigate2 “http://www.ucsd.edu“

‘ POST url, formDataBrowser.Navigate2 “http://www.ucsd.edu”, postData

Page 10: CSE 190: Internet E-Commerce

IE: Hosting the ControlVB, VJ++ Hosting:1. Add “Microsoft Internet Controls” to References2. Either:

– Set InternetExplorer1 = new InternetExplorer– Or: Drag WebBrowserCtl onto new form

VC++ hosting (ATL):1. Create new ATL Object (HTMLControl)2. Within OnCreate() method, call

wnd.CreateControl( IDH_ATLWBHOST )3. SetExternalDispatch( (IAtlWbHostUI*) this );4. Fetch the pointer to the browser:

wnd.QueryControl( IID_IWebBrowser2, (void**) &m_spBrowser );

Page 11: CSE 190: Internet E-Commerce

Event System

• Why events?

• Event sequence for page loading

• Hooking events for individual page items

Page 12: CSE 190: Internet E-Commerce

Events: Page Loading

Simple Page:

• BeforeNavigate2

• DownloadBegin

• DownloadComplete

• NavigateComplete2

• DocumentComplete

Page 13: CSE 190: Internet E-Commerce

Events: Page Loading (cot’d)

Page With Frames:• BeforeNavigate2• DownloadBegin• DownloadComplete• NavigateComplete2• DocumentComplete (whole frame)• ...DocumentComplete (first frame)• ...DocumentComplete (second frame)• ...DocumentComplete (whole frame)

Page 14: CSE 190: Internet E-Commerce

Dynamic HTML (DHTML)

• Event Handlers: onClick (of a hyperlink), onLoad, etc.– Attached to specific elements via attributes

that denote functions invoked upon events– Java/DHTML Example 1.htm and DHTML

Example 2.htm– Other examples: Change appearance of text if

mouse over, etc.

• Server side scripts: e.g., Live wire