Cross Browser Javascript - PowerPoint PPT Presentation

About This Presentation
Title:

Cross Browser Javascript

Description:

If you don't have to, don't. If you think you might have to, ... emulates some IE 'quirks' triggered by no doctype or a doctype without 'system' Common Tips ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 21
Provided by: scott253
Category:

less

Transcript and Presenter's Notes

Title: Cross Browser Javascript


1
Cross Browser Javascript
  • Scott Koon
  • Fred Hutchinson Cancer Research Center
  • http//www.lazycoder.com
  • scott_at_lazycoder.com

2
Why bother?
  • If you dont have to, dont.
  • If you think you might have to, its better to do
    it up front.

3
What are the big differences?
  • DOM (Document Object Model) support
  • How to get a reference to an element.

4
What are the big differences?
  • DOM support
  • How to get a reference to an element.
  • Cross Browserdocument.getElementById( id
    )document.getElementsByTagName( name )
  • IE 5.5, Mozilla

5
What are the big differences?
  • DOM support
  • How to get a reference to an element.
  • IE onlydocument.elementNamedocument.allname

6
What are the big differences?
  • DOM support
  • How to get a reference to an element.
  • Netscape only.document.layersname

7
What are the big differences?
  • DOM Support
  • Navigating the DOM
  • IE and Mozilla support the standard methods

8
What are the big differences?
  • DOM Support
  • Event Model
  • IE uses window.event
  • Mozilla passes an event argument to the event
    handler.

9
What are the big differences?
  • Event model
  • Cross browse way to handle events

lta href"" onclick"handleEvent(event)"/gt ltscript
gt function handleEvent(aEvent) var theEvent
aEvent ? aEvent window.event lt/scriptgt
10
Common Tips
  • Dont test for specific browsers, test for
    functionality.

this.ie ((agt.indexOf("msie") ! -1)
(agt.indexOf("opera") -1)) this.ie3
(this.ie (this.major lt 4)) this.ie4
(this.ie (this.major 4)
(agt.indexOf("msie 4")!-1) ) this.ie4up
(this.ie (this.major gt 4)) this.ie5
(this.ie (this.major 4)
(agt.indexOf("msie 5.0")!-1) ) this.ie5_5
(this.ie (this.major 4)
(agt.indexOf("msie 5.5") !-1)) this.ie5up
(this.ie !this.ie3 !this.ie4) this.ie5_5up
(this.ie !this.ie3 !this.ie4
!this.ie5) this.ie6 (this.ie (this.major
4) (agt.indexOf("msie 6.")!-1)
) this.ie6up (this.ie !this.ie3
!this.ie4 !this.ie5 !this.ie5_5)
11
Common Tips
  • Quirks mode vs Standards mode
  • Mozilla will adapt based on the DOCTYPE

12
  • The many modes of Mozilla
  • Standards Mode
  • Almost Standards mode
  • Quirks mode

13
The many modes of Mozilla
  • Standards Mode
  • text/xml (xhtml)
  • Unknown doctype
  • Doctype html system

14
The many modes of Mozilla
  • Almost Standards mode
  • Any loose doctype
  • The IBM doctype

15
The many modes of Mozilla
  • Quirks mode
  • emulates some IE quirks
  • triggered by no doctype or a doctype without
    system

16
Common Tips
  • Whitespace nodes
  • Mozilla skips some whitespace nodes
  • Check nodeType property and only process type 1
    nodes.

17
Common Tips
  • OuterHTML and InnerText
  • only supported in IE
  • solution roll your own using __defineGetter__
    and __defineSetter__ in Mozilla.

18
InnerText for Mozilla
ltscript language"JavaScript"gt lt!-- if(HTMLElement
.innerText undefined) HTMLElement.prototype.
__defineGetter__ ("innerText", function ()
var r this.ownerDocument.createRange()
r.selectNodeContents(this) return
r.toString() ) //--gt lt/scriptgt
19
Common Tips
  • getYear() getFullYear() in IE
  • getYear() ! getFullYear() in Mozilla
  • Mozilla returns 1900 - the current year. IE for
    2005 it returns 105.

20
Public cross browser APIs
  • DynAPI - http//dynapi.sourceforge.net/
  • Xlib, XC - http//cross-browser.com/
Write a Comment
User Comments (0)
About PowerShow.com