IE6下focus與blur錯(cuò)亂的解決方案
復(fù)制代碼 代碼如下:
body
textarea/textarea
hello
script
window.onblur=function(){
document.title= ’blur:’Math.random() ;
}
window.onfocus=function(){
document.title= ’focus:’Math.random() ;
}
/script
/body
這應(yīng)該是一個(gè)很常見的需求 , 例如,當(dāng)前窗口定期更新數(shù)據(jù),而窗口失焦則減少信息更新頻率 。IE6的bug導(dǎo)致的配對(duì)混亂卻會(huì)打亂我們的計(jì)劃 。
上網(wǎng)查也沒查出關(guān)于這個(gè)bug的官方說明與推薦解決方案,只好自己生更的實(shí)現(xiàn)一個(gè)解決方案 。
代碼如下:
復(fù)制代碼 代碼如下:
body
textarea/textarea
hello
script
(function(){
var focusTimer = 0;
function myBlur(){
document.title= ’blur:’Math.random() ;
}
function myFocus(){
clearTimeout(focusTimer);
focusTimer = setTimeout(function(){
document.title = ’focus:’Math.random() ;
},10);
}
window.onfocus = document.body.onfocusin = myFocus;
window.onblur = document.body.onfocusout = myBlur;
}());
/script
/body
大略原理是:找到很多可能觸發(fā)onfocus與onblur的時(shí)機(jī),所有的onblur都立即執(zhí)行,而onfocus則延時(shí)10毫秒懶惰執(zhí)行 。
結(jié)果是:雖說有時(shí)多執(zhí)行了幾次myFocus與myBlur , 但能保證窗口狀態(tài)的正確性 。
方法可能有點(diǎn)山寨,不過一時(shí)沒想到更好的辦法 , 這樣也暫時(shí)能解個(gè)燃眉之急 。
相關(guān)經(jīng)驗(yàn)推薦
- IE6下不能設(shè)置height:1px的元素是什么原因如何解決
- IE 3px bug IE6 兩個(gè)div有間隙的問題
- expression CSS表達(dá)式解決IE6 position:fixed無效問題
- IE6瀏覽器下resize事件被執(zhí)行了多次解決方法
- CSS針對(duì)IE6實(shí)現(xiàn)網(wǎng)頁圖片底部留出空白的方法
- IE6圖片元素img下出現(xiàn)多余空白的問題
- 多出一行字 解決在IE6下文字溢出的解決方法小結(jié)
- IE6的雙倍,3px,注釋引起的文字錯(cuò)位等幾個(gè)BUG解決方法
- IE6 fixed的完美解決方案
- IE6中a標(biāo)簽同時(shí)使用inline-block與text-indent時(shí)出現(xiàn)的BUG
