Differences between Firefox, ie, Safari, chrome, and operabrowsers

Source: Internet
Author: User

1. How to identify a browser
You can use window. Navigator. useragent to retrieve the feature string for recognition.

 

2. How to obtain scrolltop, scrollleft, clientwidth, and clientheight
HTML with doctype differs from. Safari is also different from other browsers.
Ie、firefox1_chromew.opera, when taking doctype, documentobtains four attributes through document.doc umentelement. When doctype is not included, You need to obtain it through document. Body.
In either case, Safari needs to use document. Body to obtain scrolltop and scrollleft. However, if you use doctype, you can use document.doc umentelement to obtain clientwidth and clientheight.
Function getdocumentbody (){
Return (document. compatmode & document. compatmode! = "Backcompat ")? Document.doc umentelement: Document. Body;
}

// Unified interface for obtaining scrolltop from various browsers
Function getscrolltop (){
If (/Safari/I .exe C (window. Navigator. useragent) {return document. Body. scrolltop ;}
Else return getdocumentbody (). scrolltop;
}

// Unified interface for obtaining scrollleft from various browsers
Function getscrollleft (){
If (/Safari/I .exe C (window. Navigator. useragent) {return document. Body. scrollleft ;}
Else return getdocumentbody (). scrollleft;
}

Function getclientwidth (){
Return getdocumentbody (). clientwidth;
}

Function getclientheight (){
Return getdocumentbody (). clientheight;
}

3. Transparent IFRAME background
Difference: IE needs to set allowtranspancy = "true" in IFRAME. other browsers support transparent background by default.

 

4. url encoding support
Such address http://www.baidu.co % 6d
Supported by IE, Safari, chrome, and opera, but not by ff. In supported browsers, except FF will not translate http://www.baidu.co % 6D/back to http://www.baidu.com, other browsers will perform ASCII Decoding

 

5. IFRAME height determination
After loading IFRAME, IE8, FF, opera, Safari, and chrome get the frame height using the following method:
This. Height = This. contentdocument. Body. offsetheight;
IE6 obtains the frame height using the following method:
This. Height = This. Document. Body. scrollheight;

The judgment method is as follows (this represents the iframe dom object ):
If (this. contentdocument & this. contentdocument. Body. offsetheight ){
This. Height = This. contentdocument. Body. offsetheight;
} Else if (this. Document & this. Document. Body. scrollheight ){
This. Height = This. Document. Body. scrollheight;
}
Note: The document attribute of IFRAME refers to its parent document, and document refers to the document contained in it

6. trigger of the mouseout event
An example: a div contains a SELECT statement. When you move the IE cursor to the select option pop-up option, its parent node is subject to a mouseout event. FF, Safari, chrome, and opera won't have this problem.
Solution: When the DIV handles the mouseout event, ie determines:
If (window. event. toelement! = NULL ){
// Indicates that the cursor is removed from the DIV
}

 

7. Bind event processing functions
IE supports attachevent
Firefox, chrome, and Safari support addeventlistener
Opera supports both

Example:
If (/. * (Firefox | safari | chrome). */. Exec (window. Navigator. useragent )){
Window. addeventlistener ('load', adjustpage, false );
}
Else {
Window. attachevent ('onload', adjustpage );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.