出現(xiàn)問題的模塊:
燕麥企業(yè)云盤 后臺管理和購買中心
通過不停注釋代碼, 我一步步縮小問題代碼范圍, 最終定位為IE8注冊window的resize事件有問題
有問題的代碼:
angular.module("commons.directives").directive("qyResize", [
'$window',
qyResize
]);
function qyResize($window) {
'use strict';
return {
restrict: 'EA',
replace: false,
transclude: false,
link: function (scope, elem, attrs) {
$(window).resize(function () {
location.reload();
});
}
};
}
修復以后的代碼:
angular.module("commons.directives").directive("qyResize", [
'$window',
qyResize
]);
function qyResize($window) {
'use strict';
return {
restrict: 'EA',
replace: false,
transclude: false,
link: function (scope, elem, attrs) {
var winWidth = $(window).width(),
winHeight = $(window).height(),
resizeTimeout = null;
$(window).resize(function () {
var onResize = function () {
//The method which alter some css properties triggers
//window.resize again and it ends in an infinite loop
location.reload();
};
//New height and width
var winNewWidth = $(window).width(),
winNewHeight = $(window).height();
// compare the new height and width with old one
if (winWidth != winNewWidth || winHeight != winNewHeight) {
window.clearTimeout(resizeTimeout);
resizeTimeout = window.setTimeout(onResize, 10);
}
//Update the width and height
winWidth = winNewWidth;
winHeight = winNewHeight;
});
}
};
}
這個問題是因為IE8的resize事件觸發(fā)有問題, 它在剛進入頁面時一定會觸發(fā)該事件.
angular版本的登錄和注冊功能沒有問題是因為他們中沒有用到qy-resize