在Mootools 1.2正式版中,有一个很小很诡异的bug,一般碰不上这么bt的事情。在页面里面有iframe,并且会涉及到跨域的问题时,若在页面执行过程中改变代理脚本,在改变代理脚本的前后会出现JavaScript线程假死的情况——所有的JavaScript事件都会失去响应,而此时若还原默认的脚本设置,则又可恢复正常。后来发现问题出在Event对象中,有这么几行:

win = win || window;
var doc = win.document;
event = event || win.event;

经测试,发现在这里居然取不到win.document——拒绝访问(Permission Denied)!打印了一下win的属性,发现已经是被mootools打包后的window对象了,但不知为何里面的所有属性都是拒绝访问。直接很裸地试着直接取“document”,居然成功了!修改此段代码如下:

win = win || window;
var doc = document;
try {
    doc = win.document || document;
    event = event || win.event;
}
catch (e) {
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.