YUI在IE浏览器里DOM元素加载很快的时候window.onload执行的要比domready快。这个执行顺序的问题应该算是一个bug,但是在jQuery我做个类似的实验,发现jQuery里没有类似的问题。
对这个问题确实比较好奇,看了看YUI2和jQuery关于DOM ready实现的部分源码。在IE实现DOM Ready基本都是用Diego Perini提出的方法:http://javascript.nwbox.com/IEContentLoaded/
但是jQuery的开发者已经意识到IE浏览器有时存在onload执行的比DOM Ready快的问题,因为这样确实会出现风险。jQuery是这么解决的,我节选了部分解决这个问题的jQuery代码(版本-1.4.2):
DOMContentLoaded = function() {
if ( document.readyState === “complete” ) {
document.detachEvent( “onreadystatechange”, DOMContentLoaded );
jQuery.ready();
}
};
document.attachEvent(“onreadystatechange”, DOMContentLoaded);
YUI没有这样做,我估计是因为效率问题,上面的代码虽然让domready执行的比window.onload快,但是因为绑定了onreadystatechange事件,效率会低一点。
而jQuery采用了更加安全的策略,慢就慢一点,安全一点更重要。如果在使用YUI2的时候确实遇到了这个安全问题,我们也可以牺牲一点效率,修改一下YUI的源码。
终于搞清楚了,又是一个需要权衡的问题。
但是我也抛出一个我没有想明白的问题,YUI2里面为什么不去尝试
document.documentElement.doScroll(‘left’);来判断domready,而是先要在超空间先创造一个p节点,然后再doScroll,domready以后再把这个p节点清空掉,这样做有什么好呢?为什么不采用jQuery和Diego Perini的做法呢?个人觉得创造一个p节点,再释放掉效率更低呀。

在IE里,如果有iframe,doScroll不会抛出异常。同样是通过绑定onreadystatechange来解决这个问题。YUI2.8已经解决。
详见:
http://yuilibrary.com/projects/yui2/ticket/2008289
Buy:Lasix.Lipitor.Zetia.Wellbutrin SR.Benicar.Prozac.SleepWell.Seroquel.Zocor.Buspar.Nymphomax.Aricept.Lipothin.Acomplia.Ventolin.Cozaar.Amoxicillin.Female Pink Viagra.Advair.Female Cialis….
…
BUY FASHION. TOP BRANDS: GUCCI, DOLCE&GABBANA, BURBERRY, DIESEL, ICEBERG, ROBERTO CAVALLI, EMPORIO ARMANI, VERSACE…
████████►BUY VIAGRA◀███████…
████████▲▲▲▲▲▲▲▲▲████████…
Cialis UK…
Buynow it…
Cialis discount…
Buyno prescription…
aggrenox@1.now” rel=”nofollow”>.…
Buygeneric meds…
cost@of.alesse” rel=”nofollow”>..…
Buyit now…
cipro@250.mg” rel=”nofollow”>..…
Buygeneric meds…
purchase@effexor.now” rel=”nofollow”>.…
Buyno prescription…
Zyrtec…
Buydrugs without prescription…
xeloda…
Buynow…
xeloda bleeding…
Buygeneric meds…
Zoloft…
Buygeneric drugs…
zofran odt…
Buynow it…
Voltaren…
Buyno prescription…
Xenical…
Buynow…
zantac renal dosing…
Buygeneric meds…
Vitamin E…
Buynow…
buy liposomal lidocaine 4% cream maxilene…
Buywithout prescription…
Zoloft…
Buyit now…
zyrtec anticolinergici effect…
Buyno prescription…
gilbert’s syndrome tylenol…
Buygeneric meds…
side effect of zoloft…
Buyno prescription…
pyrantel pamoate gets rid of which worms…
Buydrugs without prescription…
Pyridium…
Buydrugs without prescription…
Pyrantel Pamoate…
Buygeneric meds…
Yaz…
Buygeneric pills…
Claritin@Claritin.Claritin” rel=”nofollow”>..…
Buyit now…
do@you.need.to.fast.for.prograf.levels” rel=”nofollow”>……
Buywithout prescription…
.…
Buydrugs without prescription…
purpose@of.advair” rel=”nofollow”>.…
Buygeneric meds…
……
Buydrugs without prescription…
if@you.are.allergic.to.ceclor.can.you.take.augmentin” rel=”nofollow”>……
Buywithout prescription…
bulk@coral.calcium.powder” rel=”nofollow”>..…
Buygeneric drugs…
does@clonidine.and.lamisil.interaction” rel=”nofollow”>..…
Buywithout prescription…
dried@neem.leaves” rel=”nofollow”>……
Buywithout prescription…
crestor@statin.drugs” rel=”nofollow”>……
Buyit now…
sexual@side.effects.of.lexapro.vs.paxil” rel=”nofollow”>..…
Buynow it…
aciphex@vs.nexium” rel=”nofollow”>..…
Buygeneric drugs…
.…
Buygeneric drugs…
pulmicort@or.xopenex.first.when.using.both” rel=”nofollow”>……
Buyit now…
methotrexate@and.placenta.acretia” rel=”nofollow”>.…
Buygeneric drugs…
where@to.buy.acai.berry.zen” rel=”nofollow”>……
Buyno prescription…
flomax@in.dogs” rel=”nofollow”>.…
Buyit now…
..…
Buynow it…