SlideShare ist ein Scribd-Unternehmen logo
1 von 35
WEB前端标准在各浏览器中的实现差异 路人甲 2010-08-28 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
标准都说了什么? 文档格式:HTML 布局:CSS 与宿主环境有关脚本语言:Javascript 文档操作方式:DOM 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
主要话题 ,[object Object]
line box 与 Inline Fromatting Contexts 的理解
DOM Attributes 与 JS Object 差异
tracemonkey的脚本优化
HTTP头内编码声明在浏览器内的容错影响欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE haslayoutand Block Formatting Contexts 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 haslayout 与 Block Formatting Contexts 规范异同 'Layout' 是 IE 的专有概念,它决定了元素如何对其内容进行定位和尺寸计算,与其他元素的关系和相互作用,以及对应用还有使用者的影响。 MSDN "HasLayout" Overview  : http://msdn.microsoft.com/en-us/library/bb250481(VS.85).aspx Block Formatting Contexts(块格式化上下文)是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用。 在 BFC中,每一个元素左外边与包含块的左边相接触(对于从右到左的格式化,右外边接触右边), 即使存在浮动也是如此(尽管一个元素的内容区域会由于浮动而压缩),除非这个元素也创建了一个新的 BFC。 浮动元素、绝对定位元素、inline-blocks、table-cells、table-captions 以及 'overflow' 值不是 'visible' 的元素,会创建 BFC。 【注】:CSS3中,将Block formatting contexts 叫做 flow root。对于触发方式也做了修改:The value of ‘position’ is neither ‘static’ nor ‘relative’  见[CSS3]: http://www.w3.org/TR/css3-box/#block-level0 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 hasLayout 与 Block Formatting Contexts 规范异同 包含浮动元素特性 ( 浮动清理 ): <div style="width:300px; background:gray;"> 	<div style="float:left; background:gold;">float:left</div>  </div> <div style="width:300px; background:gray; overflow:auto;"> 	<div style="float:left; background:gold;">float:left</div> </div> 在触发 hasLayout 的元素和创建了 Block Formatting Contexts 的元素中,浮动元素参与高度的计算。 【注】:IE8 标准文档模式下触发了 haslayout 特性的元素不再拥有"清理" 浮动元素功能,它回归了标准的 Block Formatting Contexts 规范,只有创建 BFC 后才拥有此功能。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 hasLayout 与 Block Formatting Contexts 规范异同 不能与浮动元素相互覆盖特性: <div style="width:300px; height:150px; background:gray">     <div style="float:left;background:gold;margin:0 10px;" >         Float Block     </div>     <div style="background:green; zoom:1;">         Block Formatting Content/haslayout     </div> </div> <div style="width:300px; height:150px; background:gray">     <div style="float:left;background:gold;margin:0 10px;" >         Float Block     </div>     <div style="background:green; overflow:auto;">         Block Formatting Content/haslayout     </div> </div> 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 hasLayout 与 Block Formatting Contexts 规范异同 不能与浮动元素相互覆盖特性: 在触发 hasLayout 的元素和创建了 Block Formatting Contexts 的元素中,浮动元素参与高度的计算。 【注】:IE8 标准文档模式下 zoom:1 不再触发 haslayout 特性。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 hasLayout 与 Block Formatting Contexts 规范异同 在标准文档模式中,合理利用 block formating context 与 IE 的haslayout 特性实现两列文字布局。 <style>     * {margin:0;padding:0; font-size:14px;}     ol {list-style:none;width:200px;}     ol li {overflow:hidden;}     ol li strong {float:left; }     ol li p {_display:inline;overflow:auto;zoom:1;} /*用inline hack修复IE6 bug*/ </style> <ol>         <li><strong>内容:</strong><p>“地球一小时”</p></li>         <li><strong>内容.内容:</strong><p>“地球一小时”</p></li>         <li><strong>内容.容:</strong><p>“地球一小时”</p></li>         <li><strong>内容.内容.内容:</strong><p>“地球一小时”</p></li> </ol> 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE 的 hasLayout 与 Block Formatting Contexts 规范异同 利用 BFC 和 hasLayout 清理 LI 容器内浮动元素,并利用 BFC 和 haslayout  区域不与浮动框重合的特性,简单的实现两列文字布局。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
Line Box and Inline Fromatting Context  欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
Line Box 与 Inline Fromatting Context  Line Box 是个计算值,它由 line-height (height) 和 vertical-align 特性值共同决定的,多个 Line Boxs  构成了行内格式化上下文 ,[object Object]
行内框会在行框内横向排列;
'line-height' 特性值指定了每个行内非替换元素生成的行内框的 确切 高度;行内替换元素的高度由 'height' 特性值决定;
文字在行内框中垂直排列,上下空隙用半差异填补;如果字号大于行内框则文字从上下方向上溢出行内框,并可能渗入到其他行框内(行框是永远不会重叠的);
'vertical-align' 特性值指定了每个行内框的垂直对齐方式;
行框的顶边界是这一系列垂直对齐的行内框最高的顶边框,底边界是最低的底边框。
行框的高度是顶边界到底边界的距离。欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
正常 Line Box 计算示意图 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE6 IE7 IE8(Q) 下 Line Box 计算错误 正确的计算 错误的计算 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
IE6 IE7 IE8(Q) 下 Line Box 计算错误 正确的计算 错误的计算 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
DOM Attributesand javascript property 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
DOM Attributes 这需要从DOM-Level-2的附录D说起: Appendix D: ECMAScript Language Binding 根据 W3C DOM 规范附录中 DOM 对象与 ECMAScript 规范中对象的绑定关系可知,DOM 本身是一套接口实现,调用相应的方法或取得相应的属性,其返回值是严格遵循 DOM 本身规范的。而 ECMAScript 规范中描述的对象类型有其自身意义范畴,当使用 ECMAScript 语法调用 DOM 是需要将两者提供的不同对象类型间的绑定。比如某 DOM 方法返回一个 Element 对象,他被绑定到 ECMAScript 中一个对象 (Object) 上,如果对这个 Object 某属性进行赋值和取值操作,究竟是对 Object 对象本身属性还是对 Element 对象属性做相关操作呢?这就产生了二意性。由此 DOM 规范中提供了 getAttribute 与 setAttribute 方法用来明确为 Element 对象属性做赋值取值操作。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
这两者是绑定关系,但是他们都有相应的方法设置、修改和删除属性。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
HTML ELEMENT = HTML的标签属性(Element Attribute)  +  JS 对象内属性(Object  Property) <Element Attributes /> + {JS Object: Propertys} DOMObject.*Attribute? 方法用来对 Element 内 String 型属性进行处理 DOMObject.* 方法用来对 JS Objecte 内 property 属性进行处理 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
<div id="A"></div> <script> var A = document.getElementById("A"); A.setAttribute("myAttribute","DOMAttribute") A.myAttribute = "ObjectProperty"; A.innerHTML = A.getAttribute("myAttribute") + " : " + A.myAttribute; </script> IE6 IE7 IE8 print : ObjectProperty : ObjectProperty other print: DOMAttribute: ObjectProperty IE 8 以及以下版本浏览器中混淆了 DOMAttribute 和 ObjectProperty 导致以上问题出现。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
tracemonkeyscript optimization 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
tracemonkey 的脚本优化 tracemonkey 就是 Firefox 的脚本引擎啦~~ function foo(){return 2+4} ; alert(foo); Firefox print : function foo(){return 6} other print: function foo(){return 2+4} ; 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
tracemonkey 的条件函数表达式 逻辑语句中的函数定义会被转换为函数表达式,这与它本身的优化机制还有关系。 先来看对逻辑语句的优化: function foo(){     if ( true ) {         function A(){alert('A')}      }else{          function A(){alert('B')}      }      A(); }  foo(); alert(foo); 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
tracemonkey 的条件函数表达式 Firefox print : A function foo() {     function A() {         alert("A");     }     A(); } other print: B function foo(){     if ( true ) {         function A(){alert('A')}      }else{          function A(){alert('B')}      }      A(); }  Firefox 中不可能被运行到的分支被优化掉了。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
tracemonkey 的条件函数表达式 规避其优化策略,可以使用计算值代替 TRUE 。 使用计算值避免Firefox对逻辑语句的优化: function foo(){     if ( 1 ===1  ) {         function A(){alert('A')}      }else{          function A(){alert('B')}      }      A(); }  foo(); alert(foo); 这样 Firefox 就不会优化代码内容了。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery Mobile & PhoneGap
jQuery Mobile & PhoneGapjQuery Mobile & PhoneGap
jQuery Mobile & PhoneGapSwiip
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introductionihamo
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentalsrspaike
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyMark Meeker
 
AK 3 web services using apache axis
AK 3   web services using apache axisAK 3   web services using apache axis
AK 3 web services using apache axisgauravashq
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax componentsIgnacio Coloma
 
Open Source Ajax Solution @OSDC.tw 2009
Open Source Ajax  Solution @OSDC.tw 2009Open Source Ajax  Solution @OSDC.tw 2009
Open Source Ajax Solution @OSDC.tw 2009Robbie Cheng
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptYusuf Motiwala
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPMatthew Turland
 
HTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game TechHTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game Techvincent_scheib
 

Was ist angesagt? (20)

MWLUG 2017 - Elementary!
MWLUG 2017 - Elementary!MWLUG 2017 - Elementary!
MWLUG 2017 - Elementary!
 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platform
 
jQuery Mobile & PhoneGap
jQuery Mobile & PhoneGapjQuery Mobile & PhoneGap
jQuery Mobile & PhoneGap
 
Jsp
JspJsp
Jsp
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introduction
 
Ridingapachecamel
RidingapachecamelRidingapachecamel
Ridingapachecamel
 
ICEfaces and JSF 2.0 on GlassFish
ICEfaces and JSF 2.0 on GlassFishICEfaces and JSF 2.0 on GlassFish
ICEfaces and JSF 2.0 on GlassFish
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
 
HTML 5 & CSS 3
HTML 5 & CSS 3HTML 5 & CSS 3
HTML 5 & CSS 3
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
 
You suck at Memory Analysis
You suck at Memory AnalysisYou suck at Memory Analysis
You suck at Memory Analysis
 
Looking into HTML5
Looking into HTML5Looking into HTML5
Looking into HTML5
 
AK 3 web services using apache axis
AK 3   web services using apache axisAK 3   web services using apache axis
AK 3 web services using apache axis
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Open Source Ajax Solution @OSDC.tw 2009
Open Source Ajax  Solution @OSDC.tw 2009Open Source Ajax  Solution @OSDC.tw 2009
Open Source Ajax Solution @OSDC.tw 2009
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious Javascript
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTP
 
HTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game TechHTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game Tech
 

Andere mochten auch

Positive psychology
Positive psychologyPositive psychology
Positive psychologyOpen Party
 
Android 开源社区,10年后的再思考
Android 开源社区,10年后的再思考Android 开源社区,10年后的再思考
Android 开源社区,10年后的再思考Open Party
 
Applying BDD in refactoring
Applying BDD in refactoringApplying BDD in refactoring
Applying BDD in refactoringOpen Party
 
Java mobile 移动应用开发
Java mobile 移动应用开发Java mobile 移动应用开发
Java mobile 移动应用开发Open Party
 
Sunshine library introduction
Sunshine library introductionSunshine library introduction
Sunshine library introductionOpen Party
 
移动广告不是网盟
移动广告不是网盟移动广告不是网盟
移动广告不是网盟Open Party
 

Andere mochten auch (7)

Positive psychology
Positive psychologyPositive psychology
Positive psychology
 
Android 开源社区,10年后的再思考
Android 开源社区,10年后的再思考Android 开源社区,10年后的再思考
Android 开源社区,10年后的再思考
 
Applying BDD in refactoring
Applying BDD in refactoringApplying BDD in refactoring
Applying BDD in refactoring
 
Java mobile 移动应用开发
Java mobile 移动应用开发Java mobile 移动应用开发
Java mobile 移动应用开发
 
Sunshine library introduction
Sunshine library introductionSunshine library introduction
Sunshine library introduction
 
移动广告不是网盟
移动广告不是网盟移动广告不是网盟
移动广告不是网盟
 
Frases ilustradas
Frases ilustradasFrases ilustradas
Frases ilustradas
 

Ähnlich wie Web前端标准在各浏览器中的实现差异

IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008Association Paris-Web
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersTodd Anglin
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Steve Souders
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008Volkan Unsal
 
IPhone Web Development With Grails from CodeMash 2009
IPhone Web Development With Grails from CodeMash 2009IPhone Web Development With Grails from CodeMash 2009
IPhone Web Development With Grails from CodeMash 2009Christopher Judd
 
Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Estelle Weyl
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Guillaume Laforge
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performanceGeorge Ang
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web PerformanceEric ShangKuan
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기YoungSu Son
 
Wai Aria - An Intro
Wai Aria - An IntroWai Aria - An Intro
Wai Aria - An IntroMatt Machell
 
What's New in Web Development
What's New in Web DevelopmentWhat's New in Web Development
What's New in Web DevelopmentKonstantin Käfer
 
支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒Toki Kanno
 

Ähnlich wie Web前端标准在各浏览器中的实现差异 (20)

IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
Think jQuery
Think jQueryThink jQuery
Think jQuery
 
HTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi LHTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi L
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008
 
New Browsers
New BrowsersNew Browsers
New Browsers
 
IPhone Web Development With Grails from CodeMash 2009
IPhone Web Development With Grails from CodeMash 2009IPhone Web Development With Grails from CodeMash 2009
IPhone Web Development With Grails from CodeMash 2009
 
前端概述
前端概述前端概述
前端概述
 
Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performance
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
GWT
GWTGWT
GWT
 
php
phpphp
php
 
Wai Aria - An Intro
Wai Aria - An IntroWai Aria - An Intro
Wai Aria - An Intro
 
What's New in Web Development
What's New in Web DevelopmentWhat's New in Web Development
What's New in Web Development
 
支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒
 

Mehr von Open Party

食品安全与生态农业──小毛驴市民农园项目介绍
食品安全与生态农业──小毛驴市民农园项目介绍食品安全与生态农业──小毛驴市民农园项目介绍
食品安全与生态农业──小毛驴市民农园项目介绍Open Party
 
网站优化实践
网站优化实践网站优化实践
网站优化实践Open Party
 
Introduction to scientific visualization
Introduction to scientific visualizationIntroduction to scientific visualization
Introduction to scientific visualizationOpen Party
 
西藏10日游
西藏10日游西藏10日游
西藏10日游Open Party
 
企业创业融资之路
企业创业融资之路企业创业融资之路
企业创业融资之路Open Party
 
夸父通讯中间件
夸父通讯中间件夸父通讯中间件
夸父通讯中间件Open Party
 
如何做演讲
如何做演讲如何做演讲
如何做演讲Open Party
 
价值驱动的组织转型-王晓明
价值驱动的组织转型-王晓明价值驱动的组织转型-王晓明
价值驱动的组织转型-王晓明Open Party
 
淘宝广告技术部开发流程和Scrum实践
淘宝广告技术部开发流程和Scrum实践淘宝广告技术部开发流程和Scrum实践
淘宝广告技术部开发流程和Scrum实践Open Party
 
对云计算的理解
对云计算的理解对云计算的理解
对云计算的理解Open Party
 
Hs java open_party
Hs java open_partyHs java open_party
Hs java open_partyOpen Party
 
Evolutionary db development
Evolutionary db development Evolutionary db development
Evolutionary db development Open Party
 

Mehr von Open Party (15)

食品安全与生态农业──小毛驴市民农园项目介绍
食品安全与生态农业──小毛驴市民农园项目介绍食品安全与生态农业──小毛驴市民农园项目介绍
食品安全与生态农业──小毛驴市民农园项目介绍
 
Cs open-party
Cs open-partyCs open-party
Cs open-party
 
网站优化实践
网站优化实践网站优化实践
网站优化实践
 
Introduction to scientific visualization
Introduction to scientific visualizationIntroduction to scientific visualization
Introduction to scientific visualization
 
西藏10日游
西藏10日游西藏10日游
西藏10日游
 
企业创业融资之路
企业创业融资之路企业创业融资之路
企业创业融资之路
 
夸父通讯中间件
夸父通讯中间件夸父通讯中间件
夸父通讯中间件
 
如何做演讲
如何做演讲如何做演讲
如何做演讲
 
爬虫点滴
爬虫点滴爬虫点滴
爬虫点滴
 
价值驱动的组织转型-王晓明
价值驱动的组织转型-王晓明价值驱动的组织转型-王晓明
价值驱动的组织转型-王晓明
 
淘宝广告技术部开发流程和Scrum实践
淘宝广告技术部开发流程和Scrum实践淘宝广告技术部开发流程和Scrum实践
淘宝广告技术部开发流程和Scrum实践
 
对云计算的理解
对云计算的理解对云计算的理解
对云计算的理解
 
Hs java open_party
Hs java open_partyHs java open_party
Hs java open_party
 
Evolutionary db development
Evolutionary db development Evolutionary db development
Evolutionary db development
 
Douban pulse
Douban pulseDouban pulse
Douban pulse
 

Web前端标准在各浏览器中的实现差异

  • 1. WEB前端标准在各浏览器中的实现差异 路人甲 2010-08-28 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 2. 标准都说了什么? 文档格式:HTML 布局:CSS 与宿主环境有关脚本语言:Javascript 文档操作方式:DOM 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 3.
  • 4. line box 与 Inline Fromatting Contexts 的理解
  • 5. DOM Attributes 与 JS Object 差异
  • 8. IE haslayoutand Block Formatting Contexts 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 9. IE 的 haslayout 与 Block Formatting Contexts 规范异同 'Layout' 是 IE 的专有概念,它决定了元素如何对其内容进行定位和尺寸计算,与其他元素的关系和相互作用,以及对应用还有使用者的影响。 MSDN "HasLayout" Overview : http://msdn.microsoft.com/en-us/library/bb250481(VS.85).aspx Block Formatting Contexts(块格式化上下文)是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用。 在 BFC中,每一个元素左外边与包含块的左边相接触(对于从右到左的格式化,右外边接触右边), 即使存在浮动也是如此(尽管一个元素的内容区域会由于浮动而压缩),除非这个元素也创建了一个新的 BFC。 浮动元素、绝对定位元素、inline-blocks、table-cells、table-captions 以及 'overflow' 值不是 'visible' 的元素,会创建 BFC。 【注】:CSS3中,将Block formatting contexts 叫做 flow root。对于触发方式也做了修改:The value of ‘position’ is neither ‘static’ nor ‘relative’ 见[CSS3]: http://www.w3.org/TR/css3-box/#block-level0 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 10. IE 的 hasLayout 与 Block Formatting Contexts 规范异同 包含浮动元素特性 ( 浮动清理 ): <div style="width:300px; background:gray;"> <div style="float:left; background:gold;">float:left</div> </div> <div style="width:300px; background:gray; overflow:auto;"> <div style="float:left; background:gold;">float:left</div> </div> 在触发 hasLayout 的元素和创建了 Block Formatting Contexts 的元素中,浮动元素参与高度的计算。 【注】:IE8 标准文档模式下触发了 haslayout 特性的元素不再拥有"清理" 浮动元素功能,它回归了标准的 Block Formatting Contexts 规范,只有创建 BFC 后才拥有此功能。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 11. IE 的 hasLayout 与 Block Formatting Contexts 规范异同 不能与浮动元素相互覆盖特性: <div style="width:300px; height:150px; background:gray"> <div style="float:left;background:gold;margin:0 10px;" > Float Block </div> <div style="background:green; zoom:1;"> Block Formatting Content/haslayout </div> </div> <div style="width:300px; height:150px; background:gray"> <div style="float:left;background:gold;margin:0 10px;" > Float Block </div> <div style="background:green; overflow:auto;"> Block Formatting Content/haslayout </div> </div> 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 12. IE 的 hasLayout 与 Block Formatting Contexts 规范异同 不能与浮动元素相互覆盖特性: 在触发 hasLayout 的元素和创建了 Block Formatting Contexts 的元素中,浮动元素参与高度的计算。 【注】:IE8 标准文档模式下 zoom:1 不再触发 haslayout 特性。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 13. IE 的 hasLayout 与 Block Formatting Contexts 规范异同 在标准文档模式中,合理利用 block formating context 与 IE 的haslayout 特性实现两列文字布局。 <style> * {margin:0;padding:0; font-size:14px;} ol {list-style:none;width:200px;} ol li {overflow:hidden;} ol li strong {float:left; } ol li p {_display:inline;overflow:auto;zoom:1;} /*用inline hack修复IE6 bug*/ </style> <ol> <li><strong>内容:</strong><p>“地球一小时”</p></li> <li><strong>内容.内容:</strong><p>“地球一小时”</p></li> <li><strong>内容.容:</strong><p>“地球一小时”</p></li> <li><strong>内容.内容.内容:</strong><p>“地球一小时”</p></li> </ol> 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 14. IE 的 hasLayout 与 Block Formatting Contexts 规范异同 利用 BFC 和 hasLayout 清理 LI 容器内浮动元素,并利用 BFC 和 haslayout 区域不与浮动框重合的特性,简单的实现两列文字布局。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 15. Line Box and Inline Fromatting Context 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 16.
  • 23. 正常 Line Box 计算示意图 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 24. IE6 IE7 IE8(Q) 下 Line Box 计算错误 正确的计算 错误的计算 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 25. IE6 IE7 IE8(Q) 下 Line Box 计算错误 正确的计算 错误的计算 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 26. DOM Attributesand javascript property 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 27. DOM Attributes 这需要从DOM-Level-2的附录D说起: Appendix D: ECMAScript Language Binding 根据 W3C DOM 规范附录中 DOM 对象与 ECMAScript 规范中对象的绑定关系可知,DOM 本身是一套接口实现,调用相应的方法或取得相应的属性,其返回值是严格遵循 DOM 本身规范的。而 ECMAScript 规范中描述的对象类型有其自身意义范畴,当使用 ECMAScript 语法调用 DOM 是需要将两者提供的不同对象类型间的绑定。比如某 DOM 方法返回一个 Element 对象,他被绑定到 ECMAScript 中一个对象 (Object) 上,如果对这个 Object 某属性进行赋值和取值操作,究竟是对 Object 对象本身属性还是对 Element 对象属性做相关操作呢?这就产生了二意性。由此 DOM 规范中提供了 getAttribute 与 setAttribute 方法用来明确为 Element 对象属性做赋值取值操作。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 29. HTML ELEMENT = HTML的标签属性(Element Attribute) + JS 对象内属性(Object Property) <Element Attributes /> + {JS Object: Propertys} DOMObject.*Attribute? 方法用来对 Element 内 String 型属性进行处理 DOMObject.* 方法用来对 JS Objecte 内 property 属性进行处理 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 30. <div id="A"></div> <script> var A = document.getElementById("A"); A.setAttribute("myAttribute","DOMAttribute") A.myAttribute = "ObjectProperty"; A.innerHTML = A.getAttribute("myAttribute") + " : " + A.myAttribute; </script> IE6 IE7 IE8 print : ObjectProperty : ObjectProperty other print: DOMAttribute: ObjectProperty IE 8 以及以下版本浏览器中混淆了 DOMAttribute 和 ObjectProperty 导致以上问题出现。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 32. tracemonkey 的脚本优化 tracemonkey 就是 Firefox 的脚本引擎啦~~ function foo(){return 2+4} ; alert(foo); Firefox print : function foo(){return 6} other print: function foo(){return 2+4} ; 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 33. tracemonkey 的条件函数表达式 逻辑语句中的函数定义会被转换为函数表达式,这与它本身的优化机制还有关系。 先来看对逻辑语句的优化: function foo(){ if ( true ) { function A(){alert('A')} }else{ function A(){alert('B')} } A(); } foo(); alert(foo); 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 34. tracemonkey 的条件函数表达式 Firefox print : A function foo() { function A() { alert("A"); } A(); } other print: B function foo(){ if ( true ) { function A(){alert('A')} }else{ function A(){alert('B')} } A(); } Firefox 中不可能被运行到的分支被优化掉了。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 35. tracemonkey 的条件函数表达式 规避其优化策略,可以使用计算值代替 TRUE 。 使用计算值避免Firefox对逻辑语句的优化: function foo(){ if ( 1 ===1 ) { function A(){alert('A')} }else{ function A(){alert('B')} } A(); } foo(); alert(foo); 这样 Firefox 就不会优化代码内容了。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 36. tracemonkey 的条件函数表达式 这就没问题了么?还是看看结果吧: other print: B function foo(){ if ( 1===1) { function A(){alert('A')} }else{ function A(){alert('B')} } A(); } Firefox print: A function foo(){ if ( 1===1 ) { function A(){alert('A')} }else{ function A(){alert('B')} } A(); } !!??!!无语了 = =b 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 37. tracemonkey 的条件函数表达式 实际上问题是这样的: JS 引擎在处理脚本程序之前会对内容作语法整理,由于JS内没有块级作用域,函数声明会被提高到当前执行块(Global 或Function )的顶端执行。 语法树整理后代码: function foo(){ function A(){alert('A')}; function A(){alert('B')}; if ( 1===1 ) {}else{} A(); } 同名函数A覆盖前面的函数A,导致执行结果为B。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 38. tracemonkey 的条件函数表达式 tracemonkey 则处理的不是这么"规范"。这个引擎太聪明了,它认为条件语句内的函数声明应该是函数表达式,因此并不将其进行比要的语法整理。 tracemonkey 语法树整理后代码: function foo(){ var A; if ( 1===1 ) { A=function (){alert('A')}; }else{ A=function (){alert('B')}; } A(); } 同名函数表达式存在于不同分支语句中,并不产生覆盖/重写效果,实际结果为A。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 39. Encoding declaration in the browser affects the fault-tolerant 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 40. 编码声明在浏览器内的容错影响 确定一个文档的字符编码的优先级顺序(由高至低): HTTP "Content-Type" 字段中的 "charset" 参数。Content-Type: text/html; charset=ISO-8859-1 META 声明中 "http-equiv" 为 "Content-Type" 对应的值中的 "charset" 的值。<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 元素的 charset 属性。<script charset="iso-8859-1"src="XXX"></script> 我们通常情况下为页面设定的字符编码信息所指对应到浏览器内部大多是字符编码别名,如 ISO-8859-1。 指定了浏览器无法识别的字符编码别名时,浏览器参照上面的优先级顺序采用更低优先级的字符编码,以此类推。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 41. 编码声明在浏览器内的容错影响 各浏览器对于没有任何字符编码设定的页面所采用的编码类型: <!DOCTYPE html> <html> <head></head> <body> <script> document.write((document.charset || document.characterSet).toUpperCase()); </script> </body> </html> 操作系统及浏览器语言均为简体中文。页面中没有设定任何的字符编码信息,页面自身的编码为 GB2312。 当页面没有设置任何字符编码信息或者浏览器无法识别 HTTP 头字段以及 META 元素中所声明的字符编码信息时,所有浏览器均会以各自在当前语言版本下的默认字符编码显示页面。 因为页面自身的编码为 GB2312,则 Windows 平台下 IE Firefox Opera 简体中文版的默认字符编码刚好为 GB2312,所以页面中的字符显示正常。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 42. 编码声明在浏览器内的容错影响 看一组特殊的例子: <?php header("Content-Type: text/html; charset=maccyrillic"); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=b.i.g+5"/> </head> <body style="font:24px Tahoma;"> 字符編碼 --- <script> document.write((document.charset || document.characterSet).toUpperCase()); </script> </body> </html> 动态页面自身的编码为 BIG5。 IE Firefox 无法识别maccyrillic,也无法识别b.i.g+5,继而采用了当前语言版本的默认编码 GB2312,与页面自身的字符编码 BIG5 不相符,导致页面中的文字显示异常。 Chrome Safari识别maccyrillic为合法的X-MAC-CYRILLIC。不再理会更低优先级的编码设置。 Opera 无法识别maccyrillic,将b.i.g+5这种字符编码别名识别为BIG5。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 43. 编码声明在浏览器内的容错影响 出现上述现象的原因主要有三点: 各浏览器的字符编码别名表不尽相同,对同一种编码下的各种别名支持的宽泛程度不一样。像 maccyrillic这种别名在 Chrome Safari 可以识别为通用的 X-MAC-CYRILLIC1,但其他浏览器则会将其视作错误的字符编码信息处理。 各浏览器在匹配页面的字符编码与别名表中的字符编码时,匹配的方式不同。Chrome Safari Opera 会将编码类型的字符串做一个转换,过滤了除英文大小写字符、数字字符之外的字符(isASCIIAlphanumeric)。如 ISO8859_5 会以转换后的 ISO88595 与别名表中的 ISO-8859-5 转换后的 ISO88595 做比较,b.i.g+5 也会转换为 big5 与别名表中的做比较,所以浏览器可以正确识别这些设置的字符编码为浏览器内部的别名。 各浏览器的默认字符编码不同。 注 1:各浏览器均可以识别 X-MAC-CYRILLIC 这种通用的字符编码别名。 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 44. 标准相关 【分享】说说标准——关于样式的特殊性【分享】说说标准——层叠顺序(Cascading order),看看到底哪个样式在起作用【分享】说说标准——你真的了解盒子模型(box model)吗?【分享】说说标准——揭开外边距折叠(Collapsing margins)的面纱【分享】说说标准——CSS中非常重要的可视化格式模型(visual formatting model)简介 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍
  • 45. 兼容性相关 【分享】深入挖掘document.getElementsByTagName()方法的返回值 【分享】CSS Hack的基本原理、常用CSS hack及使用原则 【分享】Firefox中table元素的绝对定位子元素包含块判定错误的bug 【分享】深入挖掘 offsetParant 元素的判定 【分享】零高度的浮动元素是否不影响其他元素定位? 欢迎到CSDN的跨浏览开发论坛发帖 ^_^ 版主 WebAdvocate很彪悍