IE標準模式下關閉帶Swfupload插件的ArtDialog時報"__flash__removeCallback"未定義錯誤

問題描述

使用swfupload作爲上傳組件,artdialog作爲彈出窗口,在關閉彈出窗口時,提示“__flash__removeCallback”未定義錯誤。

原因

swfupload中的flash對象銷燬前時會回調__flash__removeCallback函數,該函數的定義如下:

// Fix Flashes own cleanup code so if the SWFMovie was removed from the page
	// it doesn't display errors.
	window["__flash__removeCallback"] = function (instance, name) {
		try {
			if (instance) {
				instance[name] = null;
			}
		} catch (flashEx) {
		
		}
	};
關閉artdialog窗口時,頁面的js等內容也隨iframe一起銷燬掉,故找不到__flash__removeCallback函數的定義。

解決方法

方法一:在關閉artdialog前,直接調用swfupload中的cleanUp函數清除影片綁定的函數,此種方法邏輯上可行但本人測試失敗,測試代碼如下:

var movieElement = swfupload.getMovieElement();
swfupload.cleanUp(movieElement);
art.dialog.close();

cleanUp函數定義如下:

// Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
// This function is called by Flash each time the ExternalInterface functions are created.
SWFUpload.prototype.cleanUp = function (movieElement) {
	// Pro-actively unhook all the Flash functions
	try {
		if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
			this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
			for (var key in movieElement) {
				try {
					if (typeof(movieElement[key]) === "function") {
						movieElement[key] = null;
					}
				} catch (ex) {
				}
			}
		}
	} catch (ex1) {
	
	}

	// Fix Flashes own cleanup code so if the SWFMovie was removed from the page
	// it doesn't display errors.
	window["__flash__removeCallback"] = function (instance, name) {
		try {
			if (instance) {
				instance[name] = null;
			}
		} catch (flashEx) {
		
		}
	};

};

方法二:在關閉artdialog前,直接移除movieElement對象,測試失敗。

var movieElement = swfupload.getMovieElement();
$(movieElement).remove();

方法三:在關閉artdialog前移除movieElement對象的父對象,測試成功。

var movieElement = swfupload.getMovieElement();
$(movieElement).prarent().remove();



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章